diff --git a/day7/main.exs b/day7/main.exs index bb87d37..55ef88b 100644 --- a/day7/main.exs +++ b/day7/main.exs @@ -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