added visualization for day 8 puzzle 2

This commit is contained in:
Louis Heredero 2024-12-08 10:18:55 +01:00
parent 1ed3f6d981
commit da0f00375b
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
3 changed files with 13 additions and 6 deletions

View File

@ -49,7 +49,7 @@
} }
} }
#let visualize(input) = { #let visualize(solve, input) = {
let (grid, by-freq, antinodes) = solve(input, return-data: true) let (grid, by-freq, antinodes) = solve(input, return-data: true)
let w = grid.first().len() let w = grid.first().len()
let h = grid.len() let h = grid.len()
@ -58,7 +58,7 @@
let n-freqs = freqs.len() let n-freqs = freqs.len()
let colors = gradient.linear(red, orange, yellow, green, aqua, blue, purple) let colors = gradient.linear(red, orange, yellow, green, aqua, blue, purple)
canvas(length: 1.75em, { canvas(length: 1.85em, {
for y in range(h) { for y in range(h) {
for x in range(w) { for x in range(w) {
draw.circle( draw.circle(
@ -94,5 +94,5 @@
8, 1, 8, 1,
solve, solve,
example: 14, example: 14,
visualize: visualize visualize: visualize.with(solve)
) )

View File

@ -1,4 +1,5 @@
#import "/src/utils.typ": * #import "/src/utils.typ": *
#import "puzzle1.typ": visualize
#let in-grid(w, h, x, y) = { #let in-grid(w, h, x, y) = {
return 0 <= x and x < w and 0 <= y and y < h return 0 <= x and x < w and 0 <= y and y < h
@ -27,7 +28,7 @@
return antinodes return antinodes
} }
#let solve(input) = { #let solve(input, return-data: false) = {
let by-freq = (:) let by-freq = (:)
let antinodes = () let antinodes = ()
@ -55,11 +56,17 @@
} }
} }
return antinodes.dedup().len() antinodes = antinodes.dedup()
return if return-data {
(grid, by-freq, antinodes)
} else {
antinodes.len()
}
} }
#show-puzzle( #show-puzzle(
8, 2, 8, 2,
solve, solve,
example: 34 example: 34,
visualize: visualize.with(solve)
) )

Binary file not shown.