AdventOfCode/2020/day6/README

56 lines
1.6 KiB
Text
Raw Permalink Normal View History

2020-12-06 06:04:15 +00:00
Day 6 Notes
+--------+
| Part 1 |
+--------+
$ elixir day6part1.exs
6585
Thoughts:
2020-12-06 07:14:45 +00:00
So far I've read the whole file into memory. I initially did that here to get the answer
2020-12-06 07:18:42 +00:00
quickly to preserve my leaderboard position 🌟, but then refactored to use File.stream!
2020-12-06 07:14:45 +00:00
to parse the file line-by-line.
This meant using Stream.chunk_by to sort into groups.
Join all the answers together, and use Enum.frequencies/1 to count all the answers (discarding
newlines).
2020-12-06 06:04:15 +00:00
+--------+
| Part 2 |
+--------+
$ elixir day6part2.exs
3276
Thoughts:
2020-12-06 07:14:45 +00:00
Not stripping the newlines came in handy here, because I could use them to count how
many people are in each group. Then I could just count the frequencies that were answered
by the whole group, and finally sum those results.
2020-12-06 06:04:15 +00:00
+------------------+
| Overall Thoughts |
+------------------+
2020-12-06 07:14:45 +00:00
I didn't get an accurate time for this one due to having lunch between parts 1 and 2 🍝.
Got the answer under an hour including lunch, but more like two hours including streaming
the file and tidying up.
Using Map.pop/2 to remove an element and return its value at the same time is probably the
most notable thing here?
2020-12-06 06:04:15 +00:00
2020-12-06 07:14:45 +00:00
I wonder if there's a more effective way to parse the stream dynamically and also strip off
the new lines?
2020-12-06 07:38:43 +00:00
** Update **
From other people's answers, taking the intersection of all the replies was the best way
to implement this. Makes sense.
I think I'm succumbing to pressure to complete quickly due to the leaderboard, and just
going with whatever works rather than reading the question properly and working out
what it's *really* asking.