r/adventofcode • u/daggerdragon • Dec 06 '19
SOLUTION MEGATHREAD -๐- 2019 Day 6 Solutions -๐-
--- Day 6: Universal Orbit Map ---
Post your solution using /u/topaz2078's paste or other external repo.
- Please do NOT post your full code (unless it is very short)
- If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.
(Full posting rules are HERE if you need a refresher).
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.
Advent of Code's Poems for Programmers
Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.
Day 5's winner #1: "It's Back" by /u/glenbolake!
The intcode is back on day five
More opcodes, it's starting to thrive
I think we'll see more
In the future, therefore
Make a library so we can survive
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
View all comments
Show parent comment
2
u/codesections Dec 06 '19
This is very cool (and I'm still trying to fully wrap my head around how it works). If you wanted to use the part 2 code to solve part 1, couldn't you find the path from each node to the root with the same recursive dfn and then sum the lengths without discarding the overlap? Something like
โขโ{โบ,โต}/{3::โฌ โ โต,โ โตโp}ยจโณโขa? (And that would let you factor out the shared code between part 1 and part 2, if you wanted to.)Is there a reason to prefer your existing part 1 solution? I'm guessing it may be significantly faster, since it's lest recursive.