AdventOfCode/2020/day7
Adam Millerchip 4955687b53 Gave up on zig 2020, restore just the elixir version 2022-11-27 15:58:41 +09:00
..
README Gave up on zig 2020, restore just the elixir version 2022-11-27 15:58:41 +09:00
day7part1.exs Gave up on zig 2020, restore just the elixir version 2022-11-27 15:58:41 +09:00
day7part2.exs Gave up on zig 2020, restore just the elixir version 2022-11-27 15:58:41 +09:00
input Gave up on zig 2020, restore just the elixir version 2022-11-27 15:58:41 +09:00

README

Day 7 Notes

+--------+
| Part 1 |
+--------+

$ elixir day7part1.exs
142

Thoughts:

First parse the input to a map of node => children, representing the requirement tree.
The question is to find the ancestors, so invert the tree.
Use MapSet to avoid duplicates.
Don't need the child count, but keep it around just in case.

+--------+
| Part 2 |
+--------+

$ elixir day7part2.exs
10219

Thoughts:

Good job I kept the child count around.
Don't need the inverted tree anymore, but can use the uninverted tree from part 1.
Just walk the tree counting the children as we go.


+------------------+
| Overall Thoughts |
+------------------+

🎄 Trees 🎄

Wondering if my use of MapSet for the inverted tree was overkill, simpler way?
I *think* I got the fundamental idea of this one, rather than just hacking together whatever works,
but seeing the other answers will be the judge of that :-)

** Update **

I should have said DAG rather than tree, as each node can have multiple parents.