2020-12-10 08:42:58 +00:00
|
|
|
Day 10 Notes
|
|
|
|
|
|
|
|
+--------+
|
|
|
|
| Part 1 |
|
|
|
|
+--------+
|
|
|
|
|
|
|
|
$ elixir day10part1.exs
|
2020-12-10 15:28:41 +00:00
|
|
|
2450
|
2020-12-10 08:42:58 +00:00
|
|
|
|
|
|
|
Thoughts:
|
|
|
|
|
|
|
|
Noticed that the questions rely on you finding some insight into the data, rather than just
|
|
|
|
implementing exactly what the instructions say.
|
|
|
|
|
|
|
|
In this case, we just need to sort the data, and compute the difference between all the pairs.
|
|
|
|
|
|
|
|
|
2020-12-10 15:28:41 +00:00
|
|
|
+--------+
|
|
|
|
| Part 2 |
|
|
|
|
+--------+
|
2020-12-10 08:42:58 +00:00
|
|
|
|
|
|
|
$ elixir day10part2.exs
|
2020-12-10 15:28:41 +00:00
|
|
|
32396521357312
|
2020-12-10 08:42:58 +00:00
|
|
|
|
|
|
|
Thoughts:
|
|
|
|
|
2020-12-10 15:28:41 +00:00
|
|
|
Fudge me this took me a long time (hours, including a walk in the park...)
|
|
|
|
|
|
|
|
I spent far too long trying to find a mathematical answer based on combinations, and went down
|
|
|
|
another rabbit hole identifying the "removable" items and then trying to calculate the answer
|
|
|
|
based on that information.
|
|
|
|
|
|
|
|
Turns out the trick I was missing is graph theory.
|
|
|
|
|
|
|
|
Finally, after drawing out the example on paper, I realised that the number of combinations
|
|
|
|
forms a directed graph, where the weight of each node inherits the weight of all its parents.
|
|
|
|
For the example case (excuse my ascii drawing skills):
|
|
|
|
|
|
|
|
0(1)-1(1)-4(1)-5(1)-|
|
|
|
|
| ` | |
|
|
|
|
|---6(2) |
|
|
|
|
| | |
|
|
|
|
|---7(4)-|
|
|
|
|
|
|
|
|
|
10(4)-11(4)
|
|
|
|
` |
|
|
|
|
12(8)-18(8)-19(8)
|
2020-12-10 08:42:58 +00:00
|
|
|
|
2020-12-10 15:28:41 +00:00
|
|
|
So just need to make an algorithm that builds this graph, by iterating the sorted list
|
|
|
|
and checking the next 3 elements, keeping track of the weights as we go. It's actually simpler
|
|
|
|
than that, because we don't need to keep the connections around, just the weightings for each node.
|
2020-12-10 08:42:58 +00:00
|
|
|
|
2020-12-10 15:28:41 +00:00
|
|
|
Finally, the weight of the max joltage adapter is the answer.
|
2020-12-10 08:42:58 +00:00
|
|
|
|
|
|
|
+------------------+
|
|
|
|
| Overall Thoughts |
|
|
|
|
+------------------+
|
|
|
|
|
2020-12-10 15:28:41 +00:00
|
|
|
Part 1 was very easy, part 2 was fiendish. Glad this wasn't an interview question. Sometimes my
|
|
|
|
brain just doesn't process certain types of problem. This was one of them. Once I made the
|
|
|
|
connection to a weighted graph it was fine.
|