aoc/20/lib/days/day6.ex

30 lines
624 B
Elixir
Raw Normal View History

2023-04-17 18:18:20 +00:00
defmodule AOC.Day6 do
def part1 do
AOC.Util.input_file(6, 1)
|> String.split("\n\n")
|> Enum.map(fn group ->
group
|> String.replace("\n", "")
|> String.to_charlist()
|> Enum.uniq()
|> Enum.count()
end)
|> Enum.sum()
end
def part2 do
AOC.Util.input_file(6, 1)
|> String.split("\n\n")
|> Enum.map(fn group ->
count = String.split(group, "\n") |> Enum.count()
group
|> String.replace("\n", "")
|> String.to_charlist()
|> Enum.frequencies()
|> Enum.count(fn {_, v} -> v == count end)
end)
|> Enum.sum()
end
end