Compare commits

..

1 Commits

Author SHA1 Message Date
Shadowfacts 75745b42b7
Day 6 2020-12-06 10:57:43 -05:00
1 changed files with 12 additions and 16 deletions

View File

@ -41,10 +41,11 @@ defmodule Day6 do
str str
|> String.replace(~r/\s/, "") |> String.replace(~r/\s/, "")
|> String.to_charlist() |> String.to_charlist()
|> Enum.into(MapSet.new()) |> MapSet.new()
end end
def questions_with_all_yes(str) do def questions_with_all_yes(str) do
people =
str str
|> String.split("\n") |> String.split("\n")
|> Enum.map(fn person -> |> Enum.map(fn person ->
@ -52,14 +53,9 @@ defmodule Day6 do
|> String.to_charlist() |> String.to_charlist()
|> MapSet.new() |> MapSet.new()
end) end)
|> Enum.reduce(nil, fn person, acc ->
case acc do
nil ->
person
_ -> people
MapSet.intersection(acc, person) |> Enum.drop(1)
end |> Enum.reduce(List.first(people), &MapSet.intersection/2)
end)
end end
end end