advent_of_code/lib/aoc_runner.ex
Caleb Webber c2933897db switch to project format
Fixed a bug in the day1 solution where
the list of totals could add the "current
sum" for a given elf to the list each time
a new entry was added e.g. an input like,

100
200
300

could result in a list like,

[300, 200, 100].

Now we reorder the list at each "reset" (empty line).
2023-10-27 15:47:49 -04:00

15 lines
369 B
Elixir

defmodule AOCRunner do
def run(advent) do
result = IO.stream() |>
Enum.reduce_while(
advent.init_state(),
fn line, acc -> line
|> advent.to_command()
|> advent.apply_command(acc)
|> then(fn acc -> if elem(acc, 2) do {:halt, acc} else {:cont, acc} end end)
end
)
IO.puts(advent.get_answer(result))
end
end