Trimming input. Fixing my bug where i hardcoded part 2.

master
Dustin Swan 4 weeks ago
parent 5e3db65175
commit 8a63be7ba3
Signed by: dustinswan
GPG Key ID: AB49BD6B2B3A6377

@ -2,6 +2,7 @@ defmodule Day7 do
def run do
lines =
File.read!("test.txt")
|> String.trim()
|> String.split("\n")
|> Enum.map(fn l -> String.split(l, ~r{\D+}) |> Enum.map(&String.to_integer(&1)) end)
|> Enum.map(fn [head | tail] -> {head, tail} end)
@ -23,7 +24,7 @@ defmodule Day7 do
# base case is 2 elements. if any succeed, return true
[_, _] -> Enum.any?(branches, fn n -> n == total end)
# recurse by trying each branch, subbing the first 2 elements with the new combined element
[_, _ | rest] -> Enum.any?(branches, &valid?({total, [&1 | rest]}, 2))
[_, _ | _] -> Enum.any?(branches, &valid?({total, [&1 | rest]}, part))
end
end

Loading…
Cancel
Save