Mixifying

This commit is contained in:
2025-12-13 15:42:22 -05:00
parent dbe0615d0e
commit d34cf3575c
10 changed files with 138 additions and 15 deletions

18
lib/advent_of_code.ex Normal file
View File

@@ -0,0 +1,18 @@
defmodule AdventOfCode do
@moduledoc """
Documentation for `AdventOfCode`.
"""
@doc """
Hello world.
## Examples
iex> AdventOfCode.hello()
:world
"""
def hello do
:world
end
end

8
lib/year_2025/day1.exs Normal file
View File

@@ -0,0 +1,8 @@
filepath = Path.join([File.cwd!, "lib", "year_2025", "day1_input.txt"])
ops = File.stream!(filepath)
|>Stream.map(&String.trim_trailing/1)
|>Enum.to_list
{_, zeroes} = AdventOfCode.Year2025.Dial.rotate(ops)
IO.puts(zeroes)

4059
lib/year_2025/day1_input.txt Normal file

File diff suppressed because it is too large Load Diff

38
lib/year_2025/dial.ex Normal file
View File

@@ -0,0 +1,38 @@
defmodule AdventOfCode.Year2025.Dial do
# Initial conditions
def rotate(operations), do: rotate(50, operations, 0)
# When no operations remain, return the number of zeroes
def rotate(index, [], zeroes), do: { index, zeroes }
# Compute the new dial position
def rotate(index, [head | tail], zeroes) do
{ new_index, _crosses } = case head do
"R" <> number -> rotate_right(index, String.to_integer(number))
"L" <> number -> rotate_left(index, String.to_integer(number))
end
case new_index do
0 -> rotate(new_index, tail, zeroes+1)
_ -> rotate(new_index, tail, zeroes)
end
end
defp rotate_right(index, number) do
crosses = div(number, 100)
diff = index + rem(number, 100)
case diff do
diff when diff <= 99 -> { diff, crosses }
diff when diff > 99 -> { diff - 100, crosses + 1 }
end
end
defp rotate_left(index, number) do
crosses = div(number, 100)
diff = index - rem(number, 100)
case diff do
diff when diff >= 0 -> { diff, crosses }
diff when diff < 0 -> { diff + 100, crosses + 1 }
end
end
end