Powered by AppSignal & Oban Pro

Day 1: Secret Entrance

2025/day01.livemd

Day 1: Secret Entrance

Mix.install([:kino])

Section

input =
  Kino.Input.textarea("input", monospace: true)
input
|> Kino.Input.read()
|> String.split()
|> Enum.map(fn
  "L" <> rotation -> -String.to_integer(rotation)
  "R" <> rotation -> String.to_integer(rotation)
end)
|> Enum.scan(50, fn rotation, dail -> 
    Integer.mod(dail + rotation, 100)
end)
|> Enum.count(&amp;(&amp;1 == 0))
input
|> Kino.Input.read()
|> String.split()
|> Enum.map_reduce(50, fn
  "L" <> rotation, dial ->
    rotation
    |> String.to_integer()
    |> then(
      &amp;{
        div(rem(100 - dial, 100) + &amp;1, 100),
        Integer.mod(dial - &amp;1, 100)
      }
    )

  "R" <> rotation, dial ->
    rotation
    |> String.to_integer()
    |> then(
      &amp;{
        div(dial + &amp;1, 100),
        Integer.mod(dial + &amp;1, 100)
      }
    )
end)
|> elem(0)
|> Enum.sum()