A bit more consistent

master
Dustin Swan 4 weeks ago
parent 0d62d145ab
commit f4c72675e2
Signed by: dustinswan
GPG Key ID: AB49BD6B2B3A6377

@ -8,8 +8,10 @@ defmodule Day7 do
|> Enum.map(fn [head | tail] -> {head, tail} end) |> Enum.map(fn [head | tail] -> {head, tail} end)
[ [
[&*/2, &+/2], # part 1's operatons: * and + # part 1's operatons: * and +
[&*/2, &+/2, &("#{&1}#{&2}" |> String.to_integer())] # part 2's operatons: *, +, and concat [&*/2, &+/2],
# part 2's operatons: *, +, and concat
[&*/2, &+/2, &("#{&1}#{&2}" |> String.to_integer())]
] ]
|> Enum.map(fn ops -> |> Enum.map(fn ops ->
# filter valid lines for parts 1 and 2, grab their targets, and sum them # filter valid lines for parts 1 and 2, grab their targets, and sum them
@ -25,7 +27,7 @@ defmodule Day7 do
# apply each operation to the first two operands, prepend and recurse # apply each operation to the first two operands, prepend and recurse
defp valid?({total, [a, b | rest]}, ops) do defp valid?({total, [a, b | rest]}, ops) do
Enum.any?(ops, &valid?({total, [&1.(a, b) | rest]}, ops)) Enum.any?(ops, fn op -> valid?({total, [op.(a, b) | rest]}, ops) end)
end end
end end

Loading…
Cancel
Save