r/adventofcode • • 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

Click here for full rules

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)

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!


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

EDIT: Leaderboard capped, thread unlocked at 00:38:50!

17 Upvotes

179 comments sorted by

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.

1

u/rabuf Dec 15 '19

Yeah, that would be very feasible. However, I am trying to avoid rewriting my Intcode program itself. I really like that it's become a stable core.

But yeah, it's a sound approach. I'd have to rewrite some stuff though to use it for mine. The folks using a pausing approach to I/O would find it much easier to incorporate that kind of search.

1

u/oantolin Dec 15 '19

I nearly did the "processing cloning" way, but stopped myself when I realized it would save me exactly one line of code today, namely (move (svref opposite i)), at the cost of complicating other parts. But it is a fairly easy thing to do which might pay off later.