master
Dustin Swan 4 weeks ago
parent 20b941641c
commit 5f874999ef
Signed by: dustinswan
GPG Key ID: AB49BD6B2B3A6377

@ -4,7 +4,7 @@ defmodule Day5 do
{invalidUpdates, validUpdates} = Enum.split_with(updates, &updateInvalid?(&1, rules))
IO.puts("Part 2: #{sumMiddles(validUpdates)}")
IO.puts("Part 1: #{sumMiddles(validUpdates)}")
# sort the invalid ones with a sorter that looks for [a, b] in the rules list. if [a, b] exists, sort a before b
invalidSorted =
@ -16,7 +16,7 @@ defmodule Day5 do
end
defp parseFile(file) do
# split the file by the empty line, then map splitting by newlines on both sections
# split the file on the empty line, then map splitting on newlines on both sections
[top, bottom] = File.read!(file) |> String.split("\n\n") |> Enum.map(&String.split(&1, "\n"))
rules = top |> Enum.map(&String.split(&1, "|"))
updates = bottom |> Enum.drop(-1) |> Enum.map(&String.split(&1, ","))

Loading…
Cancel
Save