A bit more consistent
This commit is contained in:
parent
0d62d145ab
commit
f4c72675e2
1 changed files with 5 additions and 3 deletions
|
|
@ -8,8 +8,10 @@ defmodule Day7 do
|
|||
|> Enum.map(fn [head | tail] -> {head, tail} end)
|
||||
|
||||
[
|
||||
[&*/2, &+/2], # part 1's operatons: * and +
|
||||
[&*/2, &+/2, &("#{&1}#{&2}" |> String.to_integer())] # part 2's operatons: *, +, and concat
|
||||
# part 1's operatons: * and +
|
||||
[&*/2, &+/2],
|
||||
# part 2's operatons: *, +, and concat
|
||||
[&*/2, &+/2, &("#{&1}#{&2}" |> String.to_integer())]
|
||||
]
|
||||
|> Enum.map(fn ops ->
|
||||
# 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
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue