DEV Community

Cover image for Cryostasis
Robert Mion
Robert Mion

Posted on • Edited on

Cryostasis

Advent of Code 2019 Day 25

Try the simulator using your puzzle input!

Intcode computer simulator

Task: Solve for X where...

Part 1

X = the password for the main airlock
Enter fullscreen mode Exit fullscreen mode

No example input given

I'll eventually learn why.

Part 1

  1. Counting callbacks

Counting callbacks

The instructions contain two links, both to puzzles from earlier days in this year:

  1. Intcode calls back to Day 9

    • Day 9 calls back to Day 5
    • Day 5 calls back to Day 2
  2. ASCII-capable calls back to Day 17

    • Day 17 calls back to Day 9, too
    • Day 9 calls back to Day 5
    • Day 5 calls back to Day 2

It seems that in order to solve Day 25's puzzle, I must build an ASCII-capable computer that can run Intcode programs.

Thus, I better attempt to solve this year's puzzles in chronological order...not in reverse.

Day 25 is on hold.

Let's start with Day 1 and work our way to the finish line: saving Santa just in the knick of time!
Previously on Day 25

...and I'm back, 24 'days' later!

Part 1 again

  1. Being so glad I've been building simulators this whole time
  2. Trying to get this darn thing to stop stalling
  3. Visualizing the map of the ship in three iterations
  4. Trying to take each item
  5. Trying dozens of item combinations
  6. Giving up before I waste too much time on this puzzle

Being so glad I've been building simulators this whole time

  • Though I didn't solve either Part of Day 21, I did build a simulator that accepted user input and turned it into ASCII commands
  • Having that simulator made building this one almost too easy
  • Within minutes I had a simulator that displayed status updates for my first two moves...
  • ...before stalling

Trying to get this darn thing to stop stalling

  • Any time I tried moving a second time, the simulator would stall
  • Clearly, my while loop was unexpectedly running forever
  • Was it the conditions I used?
  • Could it even be something else?

May the trial and error begin.

...

I found the bugs!

The way I thought my code worked was as follows:

When the [Send command] button is pressed:
  Update the commands variable to store whatever was typed in the input field
  Reset the location trackers to 0 so that the program knows to start reading the first number in commands
  Parse each opcode, parameter mode and instruction as long as the last value in the list of outputs is not the character code for a question mark
Enter fullscreen mode Exit fullscreen mode

Silly me:

  • I forgot to account for resetting the location trackers

Also:

  • There are times when the next - or last - bit of output won't be Command?
  • I needed to pause the program when other punctuation marks were detected; namely: . and !

Pros and Cons:

  • I could now run the program without fear of it stalling
  • But I had to press the [Send command] button a ton of times to reveal subsequent prompts

Visualizing the map of the ship in three iterations

It was finally time to use my simulator to construct a map of the ship!

Iteration #1

  • I eventually realized that not all rooms are the same size Map iteration 1

Iteration #2

  • I thought I had it all figured out Map iteration 2

Iteration #3

  • At this point, I felt confident I had seen it all Map iteration 3

Trying to take each item

After map iteration #2, I thought I found the answer:

  • Navigate to Engineering
  • Take the escape pod, a heavy object
  • Navigate to Pressure-Sensitive Floor
  • Pass the test
  • Get the airlock password

Not so fast:

  • The escape pod is one of several items that causes the program to terminate

I was therefore left to try taking each item and determine the safe ones from the game-breaking ones.

You can see in map iteration #3 that I successfully identified each item's status.

Trying dozens of item combinations

  • I took all eight items
  • I made my way to the Pressure-Sensitive Floor
  • I was too heavy

Time to drop-and-take, drop-and-take, drop-and-take.

Some observations:

  • I could carry all but the candy cane and be too light
  • I could carry only a few items and be too heavy
  • The names of the items in no way seemed to indicate their relative weight
  • It seemed like carrying dark matter subtracted from my total weight, thereby counter-balancing a heavier item

Giving up before I waste too much time on this puzzle

  • After what must have been several dozen weight checks, I decided to search the Reddit Solution Megathread for today's puzzle to see whether my existing observations were accurate
  • Sadly, no one posted their perfect-weight items
  • Even if they had, it turns out everyone's items have different names
  • I found this out thanks to one commenter who also built simulators for all of 2019's puzzles
  • After running his Day 25 Part 1 simulator, I noticed it tried hundreds of item combinations before arriving at the desired output of the airlock password
  • By the end, their droid was carrying four items
  • It doesn't seem like a lot, but given the possible permutations, it was going to take me a long time to get there

I tried a few more times, but no luck.

It was time to move on from 2019.

Celebrating my accomplishments

  • I built the required ASCII-capable Intcode computer needed to solve Day 25's puzzle
  • I successfully debugged my program so I could run it without errors!
  • I built a working simulator to help me reveal the map and items in today's puzzle!
  • I've now built 10/12 Intcode computer simulators!

Bummer:

  • I didn't solve Part 1

2019: Year in review

Goodbye Intcode computer.

Farewell year 3 of 7.

Note to self: great work!

Top comments (0)