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