Solve day 5

This commit is contained in:
Aurélien Geron
2024-12-09 10:19:50 +13:00
parent 499a6f145d
commit 9808ad404c
3 changed files with 89 additions and 14 deletions
+13 -9
View File
@@ -1,16 +1,20 @@
defmodule Aoc2024.Utils do
def parse_rows_of_integers(input) do
def parse_integers(input, separator \\ ~r/\s+/) do
input
|> String.split(separator)
|> Enum.map(fn int_str ->
case int_str |> Integer.parse() do
{int, ""} -> int
_ -> raise "Invalid integer #{int_str}"
end
end)
end
def parse_rows_of_integers(input, separator \\ ~r/\s+/) do
input
|> String.split("\n", trim: true)
|> Enum.map(fn line ->
line
|> String.split(~r/\s+/)
|> Enum.map(fn int_str ->
case int_str |> Integer.parse() do
{int, ""} -> int
_ -> raise "Invalid integer #{int_str}"
end
end)
parse_integers(line, separator)
end)
end
end