this repo has no description
at master 1.5 kB view raw
1# Day 01 2 3```elixir 4Mix.install([:kino_aoc]) 5``` 6 7## Setup 8 9<!-- livebook:{"attrs":"eyJhc3NpZ25fdG8iOiJwdXp6bGVfaW5wdXQiLCJkYXkiOiIxIiwic2Vzc2lvbl9zZWNyZXQiOiJBRFZFTlRfT0ZfQ09ERV9TRVNTSU9OIiwieWVhciI6IjIwMjUifQ","chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 10 11```elixir 12{:ok, puzzle_input} = 13 KinoAOC.download_puzzle("2025", "1", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 14``` 15 16```elixir 17instructions = 18 puzzle_input 19 |> String.split("\n", trim: true) 20 |> Enum.map(fn <<dir>> <> rest -> 21 num = String.to_integer(rest) 22 23 if dir == ?R do 24 {div(num, 100), rem(num, 100)} 25 else 26 {div(num, 100), -rem(num, 100)} 27 end 28 end) 29``` 30 31<!-- livebook:{"branch_parent_index":0} --> 32 33## Part 1 34 35```elixir 36Enum.scan(instructions, 50, fn {_rot, val}, curr -> 37 Integer.mod(curr + val, 100) 38end) 39|> Enum.count(& &1 == 0) 40``` 41 42<!-- livebook:{"branch_parent_index":0} --> 43 44## Part 2 45 46```elixir 47<<0x434C49434B::40>> 48``` 49 50```elixir 51Enum.reduce(instructions, {50, 0}, fn {rot, val}, {curr, sum} -> 52 next = curr + val 53 54 pass = 55 cond do 56 curr == 0 and next < 0 -> 0 57 next not in 0..99 -> 1 58 rem(next, 100) == 0 -> 1 59 true -> 0 60 end 61 62 {Integer.mod(next, 100), sum + pass + rot} 63end) 64|> elem(1) 65``` 66 67<!-- livebook:{"offset":1270,"stamp":{"token":"XCP.fAfBqYepop325WQHLC6mJPz_Wpl7bDiz0qRbslvjG31mRJWcHALfstxgj_iOj3nf9_GCzh_WmPiNR4MnzZidF2bz_zMMXHTEo18hp1z3gQDdi5hTSO8UG4YSYnUEtGxO2g","version":2}} -->