AdventOfCode/2020/elixir/day6/day6part2.exs

21 lines
413 B
Elixir
Raw Normal View History

2020-12-06 06:04:15 +00:00
defmodule Day6Part2 do
def run do
2020-12-06 06:45:22 +00:00
File.stream!("input")
|> Stream.chunk_by(&(&1 == "\n"))
2020-12-06 06:04:15 +00:00
|> Stream.map(fn group ->
2020-12-06 07:03:34 +00:00
{count, frequencies} =
group
|> Enum.join()
|> String.to_charlist()
|> Enum.frequencies()
|> Map.pop(?\n)
2020-12-06 06:04:15 +00:00
2020-12-06 07:03:34 +00:00
Enum.count(frequencies, fn {_, v} -> v == count end)
2020-12-06 06:04:15 +00:00
end)
|> Enum.sum()
|> IO.puts()
end
end
Day6Part2.run()