Skip to content

Commit 3124e64

Browse files
committed
Solve 2024/8
1 parent ee0adc0 commit 3124e64

12 files changed

Lines changed: 176 additions & 9 deletions

File tree

BENCHMARKS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Performance results for all solved Advent of Code challenges.
44

55
## System Information
66

7-
- **Run Date:** 2026-04-05 18:51:29
7+
- **Run Date:** 2026-04-05 18:55:17
88
- **OS:** Linux 6.8.0-106-generic
99
- **CPU:** 12th Gen Intel(R) Core(TM) i7-12700H
1010

@@ -39,10 +39,11 @@ Performance results for all solved Advent of Code challenges.
3939
| 5 | [Print Queue](https://adventofcode.com/2024/day/5) | 🟢 | 14.38 |
4040
| 6 | [Guard Gallivant](https://adventofcode.com/2024/day/6) | 🟠 | 1234.51 |
4141
| 7 | [Bridge Repair](https://adventofcode.com/2024/day/7) | 🟡 | 627.55 |
42+
| 8 | [Resonant Collinearity](https://adventofcode.com/2024/day/8) | 🟡 | 4.18 |
4243
| 12 | [Garden Groups](https://adventofcode.com/2024/day/12) | 🟠 | 68.94 |
4344
| 18 | [RAM Run](https://adventofcode.com/2024/day/18) | 🟠 | 15.75 |
4445
| 23 | [LAN Party](https://adventofcode.com/2024/day/23) | 🟠 | 45.04 |
45-
| **Total** | | | **2037.81** |
46+
| **Total** | | | **2041.99** |
4647

4748
### 2023
4849

README.md

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

lib/2024/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[Home](../../README.md) | [2015](../2015/README.md) | [2016](../2016/README.md) | [2017](../2017/README.md) | [2018](../2018/README.md) | [2019](../2019/README.md) | [2020](../2020/README.md) | [2021](../2021/README.md) | [2022](../2022/README.md) | [2023](../2023/README.md) | 2024 | [2025](../2025/README.md)
44

5-
## 20/50
5+
## 22/50
66

7-
[graph](../../wiki/tags/graph.md) `3` [grid](../../wiki/tags/grid.md) `3` [binary-search](../../wiki/tags/binary-search.md) `1` [bron-kerbosch](../../wiki/tags/bron-kerbosch.md) `1` [clique](../../wiki/tags/clique.md) `1` [cycle-detection](../../wiki/tags/cycle-detection.md) `1` [dijkstra](../../wiki/tags/dijkstra.md) `1` [disjoint-set](../../wiki/tags/disjoint-set.md) `1` [enumeration](../../wiki/tags/enumeration.md) `1` [fsm](../../wiki/tags/fsm.md) `1` [geometry2d](../../wiki/tags/geometry2d.md) `1` [lan-party](../../wiki/tags/lan-party.md) `1` [list](../../wiki/tags/list.md) `1` [maximum-clique](../../wiki/tags/maximum-clique.md) `1` [recursion](../../wiki/tags/recursion.md) `1` [regex](../../wiki/tags/regex.md) `1` [sequence](../../wiki/tags/sequence.md) `1` [simulation](../../wiki/tags/simulation.md) `1` [slow](../../wiki/tags/slow.md) `1` [sort](../../wiki/tags/sort.md) `1` [topological-sort](../../wiki/tags/topological-sort.md) `1` [validation](../../wiki/tags/validation.md) `1` [word-search](../../wiki/tags/word-search.md) `1`
7+
[grid](../../wiki/tags/grid.md) `4` [graph](../../wiki/tags/graph.md) `3` [enumeration](../../wiki/tags/enumeration.md) `2` [binary-search](../../wiki/tags/binary-search.md) `1` [bron-kerbosch](../../wiki/tags/bron-kerbosch.md) `1` [clique](../../wiki/tags/clique.md) `1` [coordinate-geometry](../../wiki/tags/coordinate-geometry.md) `1` [cycle-detection](../../wiki/tags/cycle-detection.md) `1` [dijkstra](../../wiki/tags/dijkstra.md) `1` [disjoint-set](../../wiki/tags/disjoint-set.md) `1` [fsm](../../wiki/tags/fsm.md) `1` [geometry2d](../../wiki/tags/geometry2d.md) `1` [lan-party](../../wiki/tags/lan-party.md) `1` [list](../../wiki/tags/list.md) `1` [maximum-clique](../../wiki/tags/maximum-clique.md) `1` [recursion](../../wiki/tags/recursion.md) `1` [regex](../../wiki/tags/regex.md) `1` [sequence](../../wiki/tags/sequence.md) `1` [simulation](../../wiki/tags/simulation.md) `1` [slow](../../wiki/tags/slow.md) `1` [sort](../../wiki/tags/sort.md) `1` [topological-sort](../../wiki/tags/topological-sort.md) `1` [validation](../../wiki/tags/validation.md) `1` [word-search](../../wiki/tags/word-search.md) `1`
88

99
| Day | Title | Difficulty | Tags | Source |
1010
|:---:|-------|:----------:|------|--------|
@@ -15,6 +15,7 @@
1515
| [5](https://adventofcode.com/2024/day/5) | [Print Queue](https://adventofcode.com/2024/day/5) | 🟢 | [graph](../../wiki/tags/graph.md), [topological-sort](../../wiki/tags/topological-sort.md), [sort](../../wiki/tags/sort.md) | [day_05.ex](day_05.ex) |
1616
| [6](https://adventofcode.com/2024/day/6) | [Guard Gallivant](https://adventofcode.com/2024/day/6) | 🟠 | [grid](../../wiki/tags/grid.md), [simulation](../../wiki/tags/simulation.md), [cycle-detection](../../wiki/tags/cycle-detection.md), [slow](../../wiki/tags/slow.md) | [day_06.ex](day_06.ex) |
1717
| [7](https://adventofcode.com/2024/day/7) | [Bridge Repair](https://adventofcode.com/2024/day/7) | 🟡 | [recursion](../../wiki/tags/recursion.md), [enumeration](../../wiki/tags/enumeration.md) | [day_07.ex](day_07.ex) |
18+
| [8](https://adventofcode.com/2024/day/8) | [Resonant Collinearity](https://adventofcode.com/2024/day/8) | 🟡 | [grid](../../wiki/tags/grid.md), [enumeration](../../wiki/tags/enumeration.md), [coordinate-geometry](../../wiki/tags/coordinate-geometry.md) | [day_08.ex](day_08.ex) |
1819
| [12](https://adventofcode.com/2024/day/12) | [Garden Groups](https://adventofcode.com/2024/day/12) | 🟠 | [geometry2d](../../wiki/tags/geometry2d.md), [disjoint-set](../../wiki/tags/disjoint-set.md) | [day_12.ex](day_12.ex) |
1920
| [18](https://adventofcode.com/2024/day/18) | [RAM Run](https://adventofcode.com/2024/day/18) | 🟠 | [graph](../../wiki/tags/graph.md), [grid](../../wiki/tags/grid.md), [binary-search](../../wiki/tags/binary-search.md), [dijkstra](../../wiki/tags/dijkstra.md) | [day_18.ex](day_18.ex) |
2021
| [23](https://adventofcode.com/2024/day/23) | [LAN Party](https://adventofcode.com/2024/day/23) | 🟠 | [graph](../../wiki/tags/graph.md), [clique](../../wiki/tags/clique.md), [bron-kerbosch](../../wiki/tags/bron-kerbosch.md), [maximum-clique](../../wiki/tags/maximum-clique.md), [lan-party](../../wiki/tags/lan-party.md) | [day_23.ex](day_23.ex) |

lib/2024/day_08.ex

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
defmodule AdventOfCode.Y2024.Day08 do
2+
@moduledoc """
3+
--- Day 8: Resonant Collinearity ---
4+
Problem Link: https://adventofcode.com/2024/day/8
5+
Difficulty: s
6+
Tags: grid enumeration coordinate-geometry
7+
"""
8+
alias AdventOfCode.Helpers.{InputReader, Transformers}
9+
10+
def input, do: InputReader.read_from_file(2024, 8)
11+
12+
def run(input \\ input()) do
13+
{width, height, antennas} = parse(input)
14+
15+
p1 = solve(width, height, antennas, :part1)
16+
p2 = solve(width, height, antennas, :part2)
17+
18+
{p1, p2}
19+
end
20+
21+
defp solve(width, height, antennas, part) do
22+
for {_freq, coords} <- antennas,
23+
a1 <- coords,
24+
a2 <- coords,
25+
a1 != a2,
26+
reduce: MapSet.new() do
27+
acc ->
28+
generate_antinodes(a1, a2, width, height, part)
29+
|> Enum.reduce(acc, &MapSet.put(&2, &1))
30+
end
31+
|> MapSet.size()
32+
end
33+
34+
defp generate_antinodes({x1, y1}, {x2, y2}, w, h, :part1) do
35+
dx = x2 - x1
36+
dy = y2 - y1
37+
38+
[{x1 - dx, y1 - dy}, {x2 + dx, y2 + dy}]
39+
|> Enum.filter(&in_bounds?(&1, w, h))
40+
end
41+
42+
defp generate_antinodes({x1, y1}, {x2, y2}, w, h, :part2) do
43+
dx = x2 - x1
44+
dy = y2 - y1
45+
g = Integer.gcd(abs(dx), abs(dy))
46+
step_x = div(dx, g)
47+
step_y = div(dy, g)
48+
49+
collect_line({x1, y1}, {step_x, step_y}, w, h) ++
50+
collect_line({x1, y1}, {-step_x, -step_y}, w, h)
51+
end
52+
53+
defp collect_line({x, y}, {dx, dy}, w, h) do
54+
if in_bounds?({x, y}, w, h) do
55+
[{x, y} | collect_line({x + dx, y + dy}, {dx, dy}, w, h)]
56+
else
57+
[]
58+
end
59+
end
60+
61+
defp in_bounds?({x, y}, w, h), do: x >= 0 and x < w and y >= 0 and y < h
62+
63+
def parse(data \\ input()) do
64+
lines = Transformers.lines(data)
65+
height = length(lines)
66+
width = lines |> List.first() |> String.length()
67+
68+
antennas =
69+
lines
70+
|> Enum.with_index()
71+
|> Enum.reduce(%{}, fn {line, y}, acc ->
72+
line
73+
|> String.graphemes()
74+
|> Enum.with_index()
75+
|> Enum.reduce(acc, fn
76+
{".", _}, acc -> acc
77+
{char, x}, acc ->
78+
Map.update(acc, char, [{x, y}], &[{x, y} | &1])
79+
end)
80+
end)
81+
82+
{width, height, antennas}
83+
end
84+
end

priv/data/benchmark.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,14 @@
14331433
"time_ms": 627.552,
14341434
"title": "Bridge Repair",
14351435
"year": 2024
1436+
},
1437+
"8": {
1438+
"day": 8,
1439+
"difficulty": "s",
1440+
"link": "https://adventofcode.com/2024/day/8",
1441+
"time_ms": 4.182,
1442+
"title": "Resonant Collinearity",
1443+
"year": 2024
14361444
}
14371445
},
14381446
"2025": {

priv/input_files/2024_8.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
...d............................J.................
2+
......e.............................J.............
3+
..........6............7..........................
4+
........................P7........................
5+
..................................................
6+
.........6........................................
7+
e..........................x.................E....
8+
...G...A.......d...........................o......
9+
.....A.e...........................J......8.......
10+
................6....9.....J.............E.8......
11+
..........d.9.........7..K....E...................
12+
...e.....U....9................x..K...............
13+
......A......O...........P................o.......
14+
......................x..................M..E.....
15+
........................x........p................
16+
........A..................O......................
17+
.......r.f....O.......P9..G.........m.............
18+
u...df..r...............7.........................
19+
.....g.............nXu......N.........K...........
20+
..............l..........0..............p.........
21+
.......lu...................p......o..............
22+
....g..........l........0p..G.....F...............
23+
.....................................8......F.....
24+
...................................C..............
25+
....3................G0......................M....
26+
2...f....g..........3........P......O......F......
27+
g......3.....0....H......................F..M.....
28+
.............c................m...h.....M.........
29+
...........2....l.................................
30+
..U...c......2...........................K........
31+
.D....................r.....f.....................
32+
....................N.............................
33+
.U..............h.................................
34+
...a.............u..............C.................
35+
c...Uj....a..6...H...................R............
36+
...3....j................H...............m........
37+
.......................5.......C..........4....m..
38+
......................H.........R......N....X.....
39+
.........h..2.................R................N..
40+
.......................r...........q...n..........
41+
.....c..............5.............................
42+
..a..h....D.................................n.....
43+
......qk..................D............1.....X....
44+
.k..................................q.............
45+
..k..........a.............L................1....4
46+
......k..........RQ..5.L.j..1..................4..
47+
..................................................
48+
..............L.....................oX............
49+
........Q.............L.........n.................
50+
...........Q.D........5..........1............4...

test/2024/day_08_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule AdventOfCode.Y2024.Day08Test do
2+
@moduledoc false
3+
4+
use ExUnit.Case, async: true
5+
@moduletag :y2408
6+
7+
alias AdventOfCode.Y2024.Day08, as: Solution
8+
9+
test "Year 2024, Day 8 run/0" do
10+
assert Solution.run() == {291, 1015}
11+
end
12+
end

wiki/difficulty.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
| 2024 | [2](https://adventofcode.com/2024/day/2) | [Red-Nosed Reports](https://adventofcode.com/2024/day/2) | [sequence](tags/sequence.md), [validation](tags/validation.md) | [day_02.ex](../lib/2024/day_02.ex) |
9595
| 2024 | [4](https://adventofcode.com/2024/day/4) | [Ceres Search](https://adventofcode.com/2024/day/4) | [grid](tags/grid.md), [word-search](tags/word-search.md) | [day_04.ex](../lib/2024/day_04.ex) |
9696
| 2024 | [7](https://adventofcode.com/2024/day/7) | [Bridge Repair](https://adventofcode.com/2024/day/7) | [recursion](tags/recursion.md), [enumeration](tags/enumeration.md) | [day_07.ex](../lib/2024/day_07.ex) |
97+
| 2024 | [8](https://adventofcode.com/2024/day/8) | [Resonant Collinearity](https://adventofcode.com/2024/day/8) | [grid](tags/grid.md), [enumeration](tags/enumeration.md), [coordinate-geometry](tags/coordinate-geometry.md) | [day_08.ex](../lib/2024/day_08.ex) |
9798
| 2025 | [1](https://adventofcode.com/2025/day/1) | [Secret Entrance](https://adventofcode.com/2025/day/1) | [simulation](tags/simulation.md), [safe-dial](tags/safe-dial.md) | [day_01.ex](../lib/2025/day_01.ex) |
9899
| 2025 | [5](https://adventofcode.com/2025/day/5) | [Cafeteria](https://adventofcode.com/2025/day/5) | [simulation](tags/simulation.md), [ranges](tags/ranges.md), [interval-merging](tags/interval-merging.md) | [day_05.ex](../lib/2025/day_05.ex) |
99100
| 2025 | [8](https://adventofcode.com/2025/day/8) | [Playground](https://adventofcode.com/2025/day/8) | [union-find](tags/union-find.md) | [day_08.ex](../lib/2025/day_08.ex) |

wiki/tags/coordinate-geometry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tag: `coordinate-geometry`
2+
3+
[← Tags Index](index.md) | [← Home](../../README.md)
4+
5+
| Year | Day | Title | Difficulty | Other Tags | Source |
6+
|------|:---:|-------|:----------:|------------|--------|
7+
| 2024 | [8](https://adventofcode.com/2024/day/8) | [Resonant Collinearity](https://adventofcode.com/2024/day/8) | 🟡 | [grid](grid.md), [enumeration](enumeration.md) | [day_08.ex](../../lib/2024/day_08.ex) |

wiki/tags/enumeration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| Year | Day | Title | Difficulty | Other Tags | Source |
66
|------|:---:|-------|:----------:|------------|--------|
77
| 2024 | [7](https://adventofcode.com/2024/day/7) | [Bridge Repair](https://adventofcode.com/2024/day/7) | 🟡 | [recursion](recursion.md) | [day_07.ex](../../lib/2024/day_07.ex) |
8+
| 2024 | [8](https://adventofcode.com/2024/day/8) | [Resonant Collinearity](https://adventofcode.com/2024/day/8) | 🟡 | [grid](grid.md), [coordinate-geometry](coordinate-geometry.md) | [day_08.ex](../../lib/2024/day_08.ex) |

0 commit comments

Comments
 (0)