From 3e0f4451e09830d88e88f12cecc514ff680674f6 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Sun, 6 Dec 2020 16:03:34 +0900 Subject: [PATCH] Refactor for readability --- day6/day6part2.exs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/day6/day6part2.exs b/day6/day6part2.exs index ed74694..e727d4a 100644 --- a/day6/day6part2.exs +++ b/day6/day6part2.exs @@ -3,12 +3,14 @@ defmodule Day6Part2 do File.stream!("input") |> Stream.chunk_by(&(&1 == "\n")) |> Stream.map(fn group -> - frequencies = group |> Enum.join() |> String.to_charlist() |> Enum.frequencies() + {count, frequencies} = + group + |> Enum.join() + |> String.to_charlist() + |> Enum.frequencies() + |> Map.pop(?\n) - count = frequencies[?\n] - - Map.delete(frequencies, ?\n) - |> Enum.count(fn {_, v} -> v == count end) + Enum.count(frequencies, fn {_, v} -> v == count end) end) |> Enum.sum() |> IO.puts()