Day 6 initial solution

This commit is contained in:
Adam Millerchip 2020-12-06 15:04:15 +09:00
parent 65974e2a54
commit 07773441f7
5 changed files with 2269 additions and 1 deletions

View File

@ -2,7 +2,7 @@
My (attempted) solutions to [Advent of Code 2020](https://adventofcode.com/2020) in Elixir.
<img width="975" alt="image" src="https://user-images.githubusercontent.com/498229/101244294-f3a85380-3748-11eb-8705-cd92fa017624.png">
<img width="986" alt="image" src="https://user-images.githubusercontent.com/498229/101272911-f8661980-37d3-11eb-93c3-f767ff22a02f.png">
## Strategy

27
day6/README Normal file
View File

@ -0,0 +1,27 @@
Day 6 Notes
+--------+
| Part 1 |
+--------+
$ elixir day6part1.exs
6585
Thoughts:
+--------+
| Part 2 |
+--------+
$ elixir day6part2.exs
3276
Thoughts:
+------------------+
| Overall Thoughts |
+------------------+

18
day6/day6part1.exs Normal file
View File

@ -0,0 +1,18 @@
defmodule Day6Part1 do
def run do
File.read!("input")
|> String.trim()
|> String.split("\n\n")
|> Stream.map(fn group ->
group
|> String.replace("\n", "")
|> String.split("", trim: true)
|> Enum.frequencies()
|> Enum.count()
end)
|> Enum.sum()
|> IO.puts()
end
end
Day6Part1.run()

24
day6/day6part2.exs Normal file
View File

@ -0,0 +1,24 @@
defmodule Day6Part2 do
def run do
File.read!("input")
|> String.trim()
|> String.split("\n\n")
|> Stream.map(fn group ->
count =
group
|> String.to_charlist()
|> Enum.count(&(&1 == ?\n))
|> Kernel.+(1)
group
|> String.replace("\n", "")
|> String.split("", trim: true)
|> Enum.frequencies()
|> Enum.count(fn {_, v} -> v == count end)
end)
|> Enum.sum()
|> IO.puts()
end
end
Day6Part2.run()

2199
day6/input Normal file

File diff suppressed because it is too large Load Diff