mix format
This commit is contained in:
parent
fc5f461fe3
commit
5d59234db4
2 changed files with 18 additions and 17 deletions
|
@ -11,25 +11,25 @@ defmodule AOCRunner do
|
||||||
|
|
||||||
@spec run(advent :: Advent, part :: :part1 | :part2) :: nil
|
@spec run(advent :: Advent, part :: :part1 | :part2) :: nil
|
||||||
def run(advent, part) do
|
def run(advent, part) do
|
||||||
|
|
||||||
# runs the advent execute method with the current line,
|
# runs the advent execute method with the current line,
|
||||||
# until two empty lines are sent
|
# until two empty lines are sent
|
||||||
run_until_exit = fn line, acc ->
|
run_until_exit = fn line, acc ->
|
||||||
{_, state} = acc
|
{_, state} = acc
|
||||||
|
|
||||||
put_elem(acc, 1, advent.execute(line |> String.trim(), state)) |>
|
put_elem(acc, 1, advent.execute(line |> String.trim(), state))
|
||||||
then(fn {last_line, s} ->
|
|> then(fn {last_line, s} ->
|
||||||
{(if both_empty?(line, last_line), do: :halt, else: :cont), {String.trim(line), s}}
|
{if(both_empty?(line, last_line), do: :halt, else: :cont), {String.trim(line), s}}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
IO.stream() |>
|
IO.stream()
|
||||||
Enum.reduce_while(
|
|> Enum.reduce_while(
|
||||||
{nil, advent.init_state(part)},
|
{nil, advent.init_state(part)},
|
||||||
&run_until_exit.(&1, &2)) |>
|
&run_until_exit.(&1, &2)
|
||||||
elem(1) |>
|
)
|
||||||
advent.get_answer() |>
|
|> elem(1)
|
||||||
IO.puts()
|
|> advent.get_answer()
|
||||||
|
|> IO.puts()
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
defmodule AocTest do
|
defmodule Day1Test do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest Aoc
|
|
||||||
|
|
||||||
test "greets the world" do
|
test "solve" do
|
||||||
assert Aoc.hello() == :world
|
{_, content} = File.read("./test/test1.txt")
|
||||||
|
IO.puts(Day1_2024.solve(content |> String.split("\n")))
|
||||||
|
assert 1 == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue