diff --git a/aoc_runner.ex b/aoc_runner.ex new file mode 100644 index 0000000..bd54b28 --- /dev/null +++ b/aoc_runner.ex @@ -0,0 +1,15 @@ +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 diff --git a/day1.ex b/day1.ex index 92b6605..a307198 100644 --- a/day1.ex +++ b/day1.ex @@ -41,14 +41,3 @@ defmodule Exercise1 do end end -result = IO.stream() |> - Enum.reduce_while( - Exercise1.init_state(), - fn line, acc -> line - |> Exercise1.to_command() - |> Exercise1.apply_command(acc) - |> then(fn acc -> if elem(acc, 2) do {:halt, acc} else {:cont, acc} end end) - end - ) - - IO.puts(Exercise1.get_answer(result)) diff --git a/main.exs b/main.exs new file mode 100644 index 0000000..1684bb8 --- /dev/null +++ b/main.exs @@ -0,0 +1,3 @@ +import AOCRunner +import Exercise1 +AOCRunner.run(Exercise1)