this repo has no description
at master 1.5 kB view raw
1# Day 12 2 3```elixir 4Mix.install([:kino_aoc]) 5``` 6 7## Parsing 8 9<!-- livebook:{"attrs":"eyJhc3NpZ25fdG8iOiJwdXp6bGVfaW5wdXQiLCJkYXkiOiIxMiIsInNlc3Npb25fc2VjcmV0IjoiQURWRU5UX09GX0NPREVfU0VTU0lPTiIsInllYXIiOiIyMDI1In0","chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 10 11```elixir 12{:ok, puzzle_input} = 13 KinoAOC.download_puzzle("2025", "12", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 14``` 15 16```elixir 17{areas, boxes} = 18 puzzle_input 19 |> String.split("\n\n") 20 |> List.pop_at(-1) 21``` 22 23```elixir 24areas = 25 areas 26 |> String.split("\n") 27 |> Enum.map(fn raw -> 28 [area | counts] = String.split(raw) 29 30 area = 31 area 32 |> String.trim(":") 33 |> String.split("x") 34 |> Enum.map(&String.to_integer/1) 35 |> Enum.product() 36 37 counts = Enum.map(counts, &String.to_integer/1) 38 39 {area, counts} 40 end) 41``` 42 43```elixir 44boxes = 45 boxes 46 |> Enum.map(fn <<_::binary-3>> <> rest -> 47 rest 48 |> String.to_charlist() 49 |> Enum.count(&(&1 == ?#)) 50 end) 51``` 52 53<!-- livebook:{"branch_parent_index":0} --> 54 55## Part 1 56 57```elixir 58areas 59|> Enum.count(fn {max, counts} -> 60 counts 61 |> Enum.zip_with(boxes, &*/2) 62 |> Enum.sum() 63 |> then(& &1 <= max) 64end) 65``` 66 67<!-- livebook:{"branch_parent_index":0} --> 68 69## Part 2 70 71FIN 72 73<!-- livebook:{"offset":1266,"stamp":{"token":"XCP.VAO97d30rTEs0AWIHkPD4J0fLm3S60tQ3fKoA-riReFbzMnqL1jIoxttGhvNSnCfZVNfeUBuSYVe6PrIshxVGBwjr3pjNHCyFLSb4iSPNh277lkMmh6Gtrlfr8dvsYvw0g","version":2}} -->