wip: day 1
This commit is contained in:
26
2025/day1.ex
Normal file
26
2025/day1.ex
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
ops = ["L50", "R50", "R1"]
|
||||||
|
|
||||||
|
defmodule Dial do
|
||||||
|
# Initial conditions
|
||||||
|
def rotate(operations), do: rotate(50, operations, 0)
|
||||||
|
|
||||||
|
# When no operations remain, return the number of zeroes
|
||||||
|
def rotate(_, [], zeroes), do: zeroes
|
||||||
|
|
||||||
|
# Compute the new dial position
|
||||||
|
def rotate(index, [head | tail], zeroes) do
|
||||||
|
index = case head do
|
||||||
|
"R" <> number -> index + String.to_integer(number)
|
||||||
|
"L" <> number -> index - String.to_integer(number)
|
||||||
|
end
|
||||||
|
|
||||||
|
case index do
|
||||||
|
0 -> rotate(index, tail, zeroes+1)
|
||||||
|
_ -> rotate(index, tail, zeroes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
dial = Dial.rotate(ops)
|
||||||
|
|
||||||
|
IO.puts dial
|
||||||
Reference in New Issue
Block a user