tangled
alpha
login
or
join now
hauleth.dev
/
advent-of-code
3
fork
atom
this repo has no description
3
fork
atom
overview
issues
pulls
pipelines
Day 06 of 2025
hauleth.dev
3 months ago
64ac2206
c7715b9a
verified
This commit was signed with the committer's
known signature
.
hauleth.dev
SSH Key Fingerprint:
SHA256:1hEP8QO8nM2KQfQ8jK4Q19y/CmqVZQI/cNSht3c1QlI=
+64
1 changed file
expand all
collapse all
unified
split
2025
day06.livemd
+64
2025/day06.livemd
···
1
1
+
# Day 06
2
2
+
3
3
+
```elixir
4
4
+
Mix.install([:kino_aoc])
5
5
+
```
6
6
+
7
7
+
## Setup
8
8
+
9
9
+
<!-- livebook:{"attrs":"eyJhc3NpZ25fdG8iOiJwdXp6bGVfaW5wdXQiLCJkYXkiOiI2Iiwic2Vzc2lvbl9zZWNyZXQiOiJBRFZFTlRfT0ZfQ09ERV9TRVNTSU9OIiwieWVhciI6IjIwMjUifQ","chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} -->
10
10
+
11
11
+
```elixir
12
12
+
{:ok, puzzle_input} =
13
13
+
KinoAOC.download_puzzle("2025", "6", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION"))
14
14
+
```
15
15
+
16
16
+
```elixir
17
17
+
{tasks, [ops]} =
18
18
+
puzzle_input
19
19
+
|> String.split("\n", trim: true)
20
20
+
|> Enum.split(-1)
21
21
+
```
22
22
+
23
23
+
```elixir
24
24
+
ops =
25
25
+
ops
26
26
+
|> String.split()
27
27
+
|> Enum.map(&String.to_atom/1)
28
28
+
```
29
29
+
30
30
+
## Part 1
31
31
+
32
32
+
```elixir
33
33
+
tasks
34
34
+
|> Enum.map(&String.split/1)
35
35
+
|> Enum.zip_with(fn numbers -> Enum.map(numbers, &String.to_integer/1) end)
36
36
+
|> Enum.zip(ops)
37
37
+
|> Enum.sum_by(fn
38
38
+
{nums, :+} -> Enum.sum(nums)
39
39
+
{nums, :*} -> Enum.product(nums)
40
40
+
end)
41
41
+
```
42
42
+
43
43
+
## Part 2
44
44
+
45
45
+
```elixir
46
46
+
tasks
47
47
+
|> Enum.map(&String.to_charlist/1)
48
48
+
|> Enum.zip_with(&(&1 |> List.to_string() |> String.trim()))
49
49
+
|> Enum.chunk_while(
50
50
+
[],
51
51
+
fn
52
52
+
"", acc -> {:cont, acc, []}
53
53
+
num, acc -> {:cont, [String.to_integer(num) | acc]}
54
54
+
end,
55
55
+
&{:cont, &1, []}
56
56
+
)
57
57
+
|> Enum.zip(ops)
58
58
+
|> Enum.sum_by(fn
59
59
+
{nums, :+} -> Enum.sum(nums)
60
60
+
{nums, :*} -> Enum.product(nums)
61
61
+
end)
62
62
+
```
63
63
+
64
64
+
<!-- livebook:{"offset":1229,"stamp":{"token":"XCP.uuy6Ksg23kO8DXLs0nEHWRa2q8MnTF00fl1kNBDi-xlsQ1DZ_teumvy__d8PZSNG_VIsQ9fTr1rGiHu3aFBxxeOD5uVO2plujrne43wrcKxIt7wi6AInBo9LuC1gXgwFgw","version":2}} -->