split code into modules

This commit is contained in:
Caleb Webber 2023-10-27 14:08:28 -04:00
parent 2af0a9f6c1
commit fc3afda4eb
3 changed files with 18 additions and 11 deletions

15
aoc_runner.ex Normal file
View file

@ -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

11
day1.ex
View file

@ -41,14 +41,3 @@ defmodule Exercise1 do
end end
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))

3
main.exs Normal file
View file

@ -0,0 +1,3 @@
import AOCRunner
import Exercise1
AOCRunner.run(Exercise1)