Trimming input. Fixing my bug where i hardcoded part 2.
This commit is contained in:
parent
5e3db65175
commit
8a63be7ba3
1 changed files with 2 additions and 1 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue