diff --git a/progress.png b/progress.png index 6451369..22cb021 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 93e1eaa..25b5bfc 100644 --- a/progress.yaml +++ b/progress.yaml @@ -11,4 +11,6 @@ 6: stars: 2 7: - stars: 2 \ No newline at end of file + stars: 2 +8: + stars: 1 \ No newline at end of file diff --git a/res/examples/day8.txt b/res/examples/day8.txt new file mode 100644 index 0000000..de0f909 --- /dev/null +++ b/res/examples/day8.txt @@ -0,0 +1,12 @@ +............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............ \ No newline at end of file diff --git a/src/day8/puzzle1.typ b/src/day8/puzzle1.typ new file mode 100644 index 0000000..822e1a2 --- /dev/null +++ b/src/day8/puzzle1.typ @@ -0,0 +1,51 @@ +#import "/src/utils.typ": * + +#let in-grid(w, h, x, y) = { + return 0 <= x and x < w and 0 <= y and y < h +} + +#let solve(input) = { + let by-freq = (:) + let antinodes = () + + let grid = input.split("\n").map(l => l.clusters()) + let w = grid.first().len() + let h = grid.len() + + let in-grid = in-grid.with(w, h) + + for y in range(h) { + for x in range(w) { + let c = grid.at(y).at(x) + if c == "." { + continue + } + if c not in by-freq { + by-freq.insert(c, ()) + } + + for (x2, y2) in by-freq.at(c) { + let (dx, dy) = (x2 - x, y2 - y) + let node1 = (x - dx, y - dy) + let node2 = (x2 + dx, y2 + dy) + + if in-grid(..node1) and node1 not in antinodes { + antinodes.push(node1) + } + + if in-grid(..node2) and node2 not in antinodes { + antinodes.push(node2) + } + } + by-freq.at(c).push((x, y)) + } + } + + return antinodes.len() +} + +#show-puzzle( + 8, 1, + solve, + example: 14 +) \ No newline at end of file diff --git a/src/day8/puzzle2.typ b/src/day8/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index 9aae509..16ab2a2 100644 Binary files a/src/main.pdf and b/src/main.pdf differ