From f4c72675e2d4e58c9611a8fe1d8b3372afba2a06 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Sat, 7 Dec 2024 21:55:00 -0700 Subject: [PATCH] A bit more consistent --- day7/main.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/day7/main.exs b/day7/main.exs index 7780f80..55b092b 100644 --- a/day7/main.exs +++ b/day7/main.exs @@ -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