Skip to content

Commit ee0adc0

Browse files
committed
Solve 2024/7
1 parent 9818f5d commit ee0adc0

11 files changed

Lines changed: 951 additions & 9 deletions

File tree

BENCHMARKS.md

Lines changed: 4 additions & 3 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:38:06
7+
- **Run Date:** 2026-04-05 18:51:29
88
- **OS:** Linux 6.8.0-106-generic
99
- **CPU:** 12th Gen Intel(R) Core(TM) i7-12700H
1010

@@ -38,10 +38,11 @@ Performance results for all solved Advent of Code challenges.
3838
| 4 | [Ceres Search](https://adventofcode.com/2024/day/4) | 🟡 | 15.78 |
3939
| 5 | [Print Queue](https://adventofcode.com/2024/day/5) | 🟢 | 14.38 |
4040
| 6 | [Guard Gallivant](https://adventofcode.com/2024/day/6) | 🟠 | 1234.51 |
41+
| 7 | [Bridge Repair](https://adventofcode.com/2024/day/7) | 🟡 | 627.55 |
4142
| 12 | [Garden Groups](https://adventofcode.com/2024/day/12) | 🟠 | 68.94 |
4243
| 18 | [RAM Run](https://adventofcode.com/2024/day/18) | 🟠 | 15.75 |
4344
| 23 | [LAN Party](https://adventofcode.com/2024/day/23) | 🟠 | 45.04 |
44-
| **Total** | | | **1410.26** |
45+
| **Total** | | | **2037.81** |
4546

4647
### 2023
4748

@@ -264,4 +265,4 @@ Performance results for all solved Advent of Code challenges.
264265
| 25 | [Let It Snow](https://adventofcode.com/2015/day/25) | 🟠 | 172.79 |
265266
| **Total** | | | **9158.03** |
266267

267-
**Total performance across all years: 44.78s**
268+
**Total performance across all years: 45.41s**

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-
## 18/50
5+
## 20/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` [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` [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+
[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`
88

99
| Day | Title | Difficulty | Tags | Source |
1010
|:---:|-------|:----------:|------|--------|
@@ -14,6 +14,7 @@
1414
| [4](https://adventofcode.com/2024/day/4) | [Ceres Search](https://adventofcode.com/2024/day/4) | 🟡 | [grid](../../wiki/tags/grid.md), [word-search](../../wiki/tags/word-search.md) | [day_04.ex](day_04.ex) |
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) |
17+
| [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) |
1718
| [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) |
1819
| [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) |
1920
| [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_07.ex

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
defmodule AdventOfCode.Y2024.Day07 do
2+
@moduledoc """
3+
--- Day 7: Bridge Repair ---
4+
Problem Link: https://adventofcode.com/2024/day/7
5+
Difficulty: s
6+
Tags: recursion enumeration
7+
"""
8+
alias AdventOfCode.Helpers.{InputReader, Transformers}
9+
10+
def input, do: InputReader.read_from_file(2024, 7)
11+
12+
def run(input \\ input()) do
13+
equations = parse(input)
14+
15+
p1 = run_1(equations)
16+
p2 = run_2(equations)
17+
18+
{p1, p2}
19+
end
20+
21+
defp run_1(equations) do
22+
solve(equations, [:add, :mul])
23+
end
24+
25+
defp run_2(equations) do
26+
solve(equations, [:add, :mul, :cat])
27+
end
28+
29+
defp solve(equations, ops) do
30+
equations
31+
|> Enum.filter(fn {target, [initial | rest]} ->
32+
valid?(target, initial, rest, ops)
33+
end)
34+
|> Enum.map(&elem(&1, 0))
35+
|> Enum.sum()
36+
end
37+
38+
defp valid?(target, target, [], _ops), do: true
39+
defp valid?(_target, _current, [], _ops), do: false
40+
defp valid?(target, current, [next | rest], ops) do
41+
Enum.any?(ops, fn op ->
42+
new_value = apply_op(op, current, next)
43+
new_value <= target and valid?(target, new_value, rest, ops)
44+
end)
45+
end
46+
47+
defp apply_op(:add, a, b), do: a + b
48+
defp apply_op(:mul, a, b), do: a * b
49+
defp apply_op(:cat, a, b), do: String.to_integer("#{a}#{b}")
50+
51+
def parse(data \\ input()) do
52+
data
53+
|> Transformers.lines()
54+
|> Enum.map(fn line ->
55+
[target, nums] = String.split(line, ": ")
56+
nums = nums |> String.split(" ") |> Enum.map(&String.to_integer/1)
57+
{String.to_integer(target), nums}
58+
end)
59+
end
60+
end

priv/data/benchmark.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,14 @@
14251425
"time_ms": 1234.505,
14261426
"title": "Guard Gallivant",
14271427
"year": 2024
1428+
},
1429+
"7": {
1430+
"day": 7,
1431+
"difficulty": "s",
1432+
"link": "https://adventofcode.com/2024/day/7",
1433+
"time_ms": 627.552,
1434+
"title": "Bridge Repair",
1435+
"year": 2024
14281436
}
14291437
},
14301438
"2025": {

0 commit comments

Comments
 (0)