this repo has no description

Day 06 of 2025

hauleth.dev 64ac2206 c7715b9a

verified
+64
+64
2025/day06.livemd
··· 1 + # Day 06 2 + 3 + ```elixir 4 + Mix.install([:kino_aoc]) 5 + ``` 6 + 7 + ## Setup 8 + 9 + <!-- livebook:{"attrs":"eyJhc3NpZ25fdG8iOiJwdXp6bGVfaW5wdXQiLCJkYXkiOiI2Iiwic2Vzc2lvbl9zZWNyZXQiOiJBRFZFTlRfT0ZfQ09ERV9TRVNTSU9OIiwieWVhciI6IjIwMjUifQ","chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 10 + 11 + ```elixir 12 + {:ok, puzzle_input} = 13 + KinoAOC.download_puzzle("2025", "6", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 14 + ``` 15 + 16 + ```elixir 17 + {tasks, [ops]} = 18 + puzzle_input 19 + |> String.split("\n", trim: true) 20 + |> Enum.split(-1) 21 + ``` 22 + 23 + ```elixir 24 + ops = 25 + ops 26 + |> String.split() 27 + |> Enum.map(&String.to_atom/1) 28 + ``` 29 + 30 + ## Part 1 31 + 32 + ```elixir 33 + tasks 34 + |> Enum.map(&String.split/1) 35 + |> Enum.zip_with(fn numbers -> Enum.map(numbers, &String.to_integer/1) end) 36 + |> Enum.zip(ops) 37 + |> Enum.sum_by(fn 38 + {nums, :+} -> Enum.sum(nums) 39 + {nums, :*} -> Enum.product(nums) 40 + end) 41 + ``` 42 + 43 + ## Part 2 44 + 45 + ```elixir 46 + tasks 47 + |> Enum.map(&String.to_charlist/1) 48 + |> Enum.zip_with(&(&1 |> List.to_string() |> String.trim())) 49 + |> Enum.chunk_while( 50 + [], 51 + fn 52 + "", acc -> {:cont, acc, []} 53 + num, acc -> {:cont, [String.to_integer(num) | acc]} 54 + end, 55 + &{:cont, &1, []} 56 + ) 57 + |> Enum.zip(ops) 58 + |> Enum.sum_by(fn 59 + {nums, :+} -> Enum.sum(nums) 60 + {nums, :*} -> Enum.product(nums) 61 + end) 62 + ``` 63 + 64 + <!-- livebook:{"offset":1229,"stamp":{"token":"XCP.uuy6Ksg23kO8DXLs0nEHWRa2q8MnTF00fl1kNBDi-xlsQ1DZ_teumvy__d8PZSNG_VIsQ9fTr1rGiHu3aFBxxeOD5uVO2plujrne43wrcKxIt7wi6AInBo9LuC1gXgwFgw","version":2}} -->