this repo has no description
1# Day 07 2 3```elixir 4Mix.install([:kino_aoc, :image]) 5``` 6 7## Parse 8 9<!-- livebook:{"attrs":"eyJhc3NpZ25fdG8iOiJwdXp6bGVfaW5wdXQiLCJkYXkiOiI3Iiwic2Vzc2lvbl9zZWNyZXQiOiJBRFZFTlRfT0ZfQ09ERV9TRVNTSU9OIiwieWVhciI6IjIwMjUifQ","chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 10 11```elixir 12{:ok, puzzle_input} = 13 KinoAOC.download_puzzle("2025", "7", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 14``` 15 16```elixir 17[start | rest] = String.split(puzzle_input) 18 19start_col = byte_size(start) - byte_size(String.trim_leading(start, ".")) 20``` 21 22```elixir 23splitters = 24 Enum.map(rest, fn row -> 25 row 26 |> String.to_charlist() 27 |> Enum.with_index() 28 |> Enum.filter(&(elem(&1, 0) == ?^)) 29 |> MapSet.new(&elem(&1, 1)) 30 end) 31``` 32 33## Part 1 34 35```elixir 36Enum.reduce(splitters, {MapSet.new([start_col]), 0}, fn splits, {beams, count} -> 37 import MapSet, only: [intersection: 2, difference: 2, union: 2] 38 39 hits = intersection(beams, splits) 40 new_beams = for hit <- hits, dx <- [-1, 1], into: MapSet.new(), do: hit + dx 41 beams = beams |> difference(hits) |> union(new_beams) 42 43 {beams, MapSet.size(hits) + count} 44end) 45``` 46 47## Part 2 48 49```elixir 50Enum.reduce(splitters, %{start_col => 1}, fn splits, beams -> 51 Enum.reduce(splits, beams, fn s, acc -> 52 case Map.pop(acc, s) do 53 {nil, map} -> 54 map 55 56 {count, map} -> 57 Map.merge( 58 map, 59 %{ 60 (s + 1) => count, 61 (s - 1) => count 62 }, 63 fn _k, a, b -> a + b end 64 ) 65 end 66 end) 67end) 68|> Enum.sum_by(&elem(&1, 1)) 69``` 70 71<!-- livebook:{"offset":1576,"stamp":{"token":"XCP.4O_0Nj7V9wS7w6P8UvTBgpp4vhW57_8fy1nGUUO-kK-Q74Dt1KmWL8qx_FolCKDbpEooq8lZ8yn9tXw9AlKXzLPCKp2hEtIvQvKWtBiSmje0vN9ms0Uqud5m2GxlgCHmtg","version":2}} -->