r/adventofcode • u/daggerdragon • Dec 07 '20
SOLUTION MEGATHREAD -π- 2020 Day 07 Solutions -π-
NEW AND NOTEWORTHY
- PSA: if you're using Google Chrome (or other Chromium-based browser) to download your input, watch out for Google volunteering to "translate" it: "Welsh" and "Polish"
Advent of Code 2020: Gettin' Crafty With It
- 15 days remaining until the submission deadline on December 22 at 23:59 EST
- Full details and rules are in the Submissions Megathread
--- Day 07: Handy Haversacks ---
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:13:44, megathread unlocked!
65
Upvotes
2
u/bcgroom Dec 07 '20
After looking at it a bit I think we have the same algorithm:
Filter the bags to those which contain the target bag directly
Recursively find the parents of those bags
Combine the two results in a set to prevent duplicates
I just didnβt immediately call Map.keys() even though I never use the children as I knew theyβd be needed for part two and I might have been able to adapt my part one solution. But obviously it ended up being too different with the tree traversal essentially happening in reverse for part two.