Created
December 6, 2020 07:02
-
-
Save ynonp/e1c646454d3f6fe0ea6dc1395be4a2a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Day6 do | |
def read_input do | |
File.read!("input/day6.txt") | |
|> String.split("\n\n", trim: true) | |
end | |
def get_common_answers(str) do | |
answers = String.split(str, "\n", trim: true) | |
|> Enum.map(&String.graphemes/1) | |
|> Enum.map(&(MapSet.new(&1))) | |
|> Enum.reduce(&MapSet.intersection/2) | |
end | |
def part1 do | |
read_input | |
|> Enum.map(&(String.replace(&1, "\n", ""))) | |
|> Enum.map(&(MapSet.new(String.graphemes(&1)))) | |
|> Enum.map(&(Enum.count(&1))) | |
|> Enum.sum | |
|> IO.inspect | |
end | |
def part2 do | |
read_input | |
|> Enum.map(&get_common_answers/1) | |
|> Enum.map(&(Enum.count(&1))) | |
|> Enum.sum | |
|> IO.inspect | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment