AdventOfCode/2020/elixir/day7
Adam Millerchip 39c28b5897 Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
..
README Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
day7part1.exs Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
day7part2.exs Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
input Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +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.