added visualization for day 8 puzzle 2
This commit is contained in:
parent
1ed3f6d981
commit
da0f00375b
@ -49,7 +49,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
#let visualize(input) = {
|
||||
#let visualize(solve, input) = {
|
||||
let (grid, by-freq, antinodes) = solve(input, return-data: true)
|
||||
let w = grid.first().len()
|
||||
let h = grid.len()
|
||||
@ -58,7 +58,7 @@
|
||||
let n-freqs = freqs.len()
|
||||
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 x in range(w) {
|
||||
draw.circle(
|
||||
@ -94,5 +94,5 @@
|
||||
8, 1,
|
||||
solve,
|
||||
example: 14,
|
||||
visualize: visualize
|
||||
visualize: visualize.with(solve)
|
||||
)
|
@ -1,4 +1,5 @@
|
||||
#import "/src/utils.typ": *
|
||||
#import "puzzle1.typ": visualize
|
||||
|
||||
#let in-grid(w, h, x, y) = {
|
||||
return 0 <= x and x < w and 0 <= y and y < h
|
||||
@ -27,7 +28,7 @@
|
||||
return antinodes
|
||||
}
|
||||
|
||||
#let solve(input) = {
|
||||
#let solve(input, return-data: false) = {
|
||||
let by-freq = (:)
|
||||
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(
|
||||
8, 2,
|
||||
solve,
|
||||
example: 34
|
||||
example: 34,
|
||||
visualize: visualize.with(solve)
|
||||
)
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
Reference in New Issue
Block a user