Compare commits
No commits in common. "da0f00375b3b01910fd2dc3bf9f85d65596d105a" and "5e304ef1e53eda06d449d6411612db1793847c36" have entirely different histories.
da0f00375b
...
5e304ef1e5
@ -1,11 +1,10 @@
|
|||||||
#import "/src/utils.typ": *
|
#import "/src/utils.typ": *
|
||||||
#import "@preview/cetz:0.3.1": canvas, draw
|
|
||||||
|
|
||||||
#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
|
||||||
}
|
}
|
||||||
|
|
||||||
#let solve(input, return-data: false) = {
|
#let solve(input) = {
|
||||||
let by-freq = (:)
|
let by-freq = (:)
|
||||||
let antinodes = ()
|
let antinodes = ()
|
||||||
|
|
||||||
@ -42,57 +41,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return if return-data {
|
return antinodes.len()
|
||||||
(grid, by-freq, antinodes)
|
|
||||||
} else {
|
|
||||||
antinodes.len()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#let visualize(solve, input) = {
|
|
||||||
let (grid, by-freq, antinodes) = solve(input, return-data: true)
|
|
||||||
let w = grid.first().len()
|
|
||||||
let h = grid.len()
|
|
||||||
|
|
||||||
let freqs = by-freq.keys()
|
|
||||||
let n-freqs = freqs.len()
|
|
||||||
let colors = gradient.linear(red, orange, yellow, green, aqua, blue, purple)
|
|
||||||
|
|
||||||
canvas(length: 1.85em, {
|
|
||||||
for y in range(h) {
|
|
||||||
for x in range(w) {
|
|
||||||
draw.circle(
|
|
||||||
(x, y),
|
|
||||||
radius: 0.1,
|
|
||||||
fill: gray,
|
|
||||||
stroke: none
|
|
||||||
)
|
|
||||||
|
|
||||||
for (i, freq) in freqs.enumerate() {
|
|
||||||
let col = colors.sample(i * 100% / n-freqs)
|
|
||||||
for (ax, ay) in by-freq.at(freq) {
|
|
||||||
draw.circle(
|
|
||||||
(ax, ay),
|
|
||||||
radius: 0.3,
|
|
||||||
fill: col
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (anx, any) in antinodes {
|
|
||||||
draw.rect(
|
|
||||||
(anx - 0.3, any - 0.3),
|
|
||||||
(anx + 0.3, any + 0.3),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#show-puzzle(
|
#show-puzzle(
|
||||||
8, 1,
|
8, 1,
|
||||||
solve,
|
solve,
|
||||||
example: 14,
|
example: 14
|
||||||
visualize: visualize.with(solve)
|
|
||||||
)
|
)
|
@ -1,5 +1,4 @@
|
|||||||
#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
|
||||||
@ -28,7 +27,7 @@
|
|||||||
return antinodes
|
return antinodes
|
||||||
}
|
}
|
||||||
|
|
||||||
#let solve(input, return-data: false) = {
|
#let solve(input) = {
|
||||||
let by-freq = (:)
|
let by-freq = (:)
|
||||||
let antinodes = ()
|
let antinodes = ()
|
||||||
|
|
||||||
@ -56,17 +55,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
antinodes = antinodes.dedup()
|
return antinodes.dedup().len()
|
||||||
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)
|
|
||||||
)
|
)
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user