r/adventofcode • u/daggerdragon • Dec 15 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 15 Solutions -🎄-
--- Day 15: Oxygen System ---
Post your full code 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 14's winner #1: "One Thing Leads To Another" by /u/DFreiberg!
Poem tl;dpost (but we did r, honest!), so go here to read it in full
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
On the (fifth*3) day of AoC, my true love gave to me...
FIVE GOLDEN SILVER POEMS (and one Santa Rocket Like)
- Day 10: "untitled poem" by /u/Yardboy
- Day 11: "A ROBOT TO THE RESCUE" by /u/mariusbancila
- Day 12: "Symmetry" by /u/DFreiberg
- Day 13: "untitled poem" by /u/captainAwesomePants
- Day 14: "Alchemy" by /u/captainAwesomePants (again! he's too awesome for his pants!)
- 5-Day Best-in-Show: "The Hunting of the Asteroids" by /u/DFreiberg
TBD because we forgot today % 5 == 0, we'll get back to you soon!
Enjoy your Reddit Silver/Gold, and good luck with the rest of the Advent of Code!
View all comments
Show parent comment
3
u/phil_g Dec 15 '19
I ended up doing a similar sort of multi-threaded approach, though I drove my exploration from the main thread and I set up a more format RPC-style interface to the running intcode program. Also, a rigorous depth-first search would probably be more efficient than my approach. ("Find the closest unknown position, go to it, see what's there, then repeat until there are no unknowns.")
But something that occurred to me while reading your writeup is this:
It's pretty trivial to clone a running Intcode program; just duplicate the memory, instruction pointer, and relative base. In theory, you could do your search without any backtracking. At every decision point, make a separate copy of the program for each potential direction and recurse over each one separately. Recursion terminates when the copy hits a wall. This could even be done with each copy running simultaneously in a parallel thread, feeding grid values back to a central thread via a queue.
I guess I'm going to add "process cloning" to my Intcode todo list.