Compare commits
1 Commits
75745b42b7
...
296c2e2e15
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 296c2e2e15 |
|
@ -41,21 +41,25 @@ defmodule Day6 do
|
|||
str
|
||||
|> String.replace(~r/\s/, "")
|
||||
|> String.to_charlist()
|
||||
|> MapSet.new()
|
||||
|> Enum.into(MapSet.new())
|
||||
end
|
||||
|
||||
def questions_with_all_yes(str) do
|
||||
people =
|
||||
str
|
||||
|> String.split("\n")
|
||||
|> Enum.map(fn person ->
|
||||
person
|
||||
|> String.to_charlist()
|
||||
|> MapSet.new()
|
||||
end)
|
||||
str
|
||||
|> String.split("\n")
|
||||
|> Enum.map(fn person ->
|
||||
person
|
||||
|> String.to_charlist()
|
||||
|> MapSet.new()
|
||||
end)
|
||||
|> Enum.reduce(nil, fn person, acc ->
|
||||
case acc do
|
||||
nil ->
|
||||
person
|
||||
|
||||
people
|
||||
|> Enum.drop(1)
|
||||
|> Enum.reduce(List.first(people), &MapSet.intersection/2)
|
||||
_ ->
|
||||
MapSet.intersection(acc, person)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue