From 685f39749323ab5da1140da6ccea23979d239229 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:54 -0400 Subject: [PATCH] 2021.19.1 don't keep list and mapset of resolved --- 2021/lib/2021/19.ex | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/2021/lib/2021/19.ex b/2021/lib/2021/19.ex index d06a658..c0126ac 100644 --- a/2021/lib/2021/19.ex +++ b/2021/lib/2021/19.ex @@ -34,23 +34,23 @@ aoc 2021, 19 do def union(map_sets), do: Enum.reduce(map_sets, MapSet.new(), &MapSet.union/2) def align_scanners([start | rest]) do - align_scanners(rest, [start]) + align_scanners(rest, start) end - def align_scanners(scanners, included, skipped \\ []) - def align_scanners([], included, []), do: union(included) - def align_scanners([], included, skipped) do + def align_scanners(scanners, aligned, skipped \\ []) + def align_scanners([], aligned, []), do: aligned + def align_scanners([], aligned, skipped) do IO.puts("") - align_scanners([union(included) | skipped]) + align_scanners([aligned | skipped]) end - def align_scanners([canidate | rest], included, skipped) do - case union(included) |> attempt_alignment(canidate) do + def align_scanners([canidate | rest], aligned, skipped) do + case aligned |> attempt_alignment(canidate) do :miss -> IO.write(".") - align_scanners(rest, included, [canidate | skipped]) + align_scanners(rest, aligned, [canidate | skipped]) {:ok, transformed} -> IO.write("+") - align_scanners(rest, [transformed | included], skipped) + align_scanners(rest, MapSet.union(transformed, aligned), skipped) end end