DEV Community

Cover image for Oxygen System
Robert Mion
Robert Mion

Posted on

Oxygen System

Advent of Code 2019 Day 15

Try the simulator using your puzzle input!

Simulator of Part 1

Task: Solve for X where...

Part 1

X = the fewest number of movement commands required to move the repair droid from its starting position to the location of the oxygen system
Enter fullscreen mode Exit fullscreen mode

Part 2

X = the number of minutes it will take to fill the space with oxygen
Enter fullscreen mode Exit fullscreen mode

No example input

  • Instead, several example input instructions and resulting output commands are simulated

Part 1

  1. Intcode computer: Round 7!
  2. Forget the algorithm: straight to building a simulator
  3. The simulator revealed the path!
  4. I painstakingly counted, and got the correct answer

Intcode computer: Round 7!

  • Similar to Round 5 (Day 11), I must move a robot
  • Unlike Round 5, the robot's path depends on my instructions, not just the state of the ground upon which it stands

Input rules:

Only four movement commands are understood: north (1), south (2), west (3), and east (4)

Output rules:

  • A single output: one of 0,1,2
  • 0: Wall. Didn't move.
  • 1: Open. Moved.
  • 2: Moved. At oxygen system!

Mission:

Direct the repair droid to the oxygen system and fix the problem

Forget the algorithm: straight to building a simulator

  • I have no idea how I would algorithmically solve this puzzle
  • But I do know how to build a simulator where I can listen for the next direction, run the program until it outputs another value, and update the robot's position and state of the area based on the status code

Off I go to try. Be back soon!

Ok, I'm back!

The simulator revealed the path!

  • I built the simulator assuming a 50x50 square area, with the droid starting in the middle
  • Just like in the instructions, I replace the contents of a cell with the correct object based on the status code returned after each attempted move
  • I mapped each keyboard arrow key to the four input directions to make it delightfully interactive

Here's an animation of how the simulator revealed the path
A recreation of discovering the general path

I painstakingly counted, and got the correct answer

After some back-tracking to identify all the walls, I had what I needed to count the minimum steps necessary:
Three frames showing the path

Here's a closer look at the shortest path:
Shortest path from droid to oxygen

Part 2

  1. Forget the algorithm: I'll make a GIF!
  2. To my delight, it was the correct answer!

Forget the algorithm: I'll make a GIF!

  • 313 frames
  • Each crafted individually
  • Using letters from the alphabet to keep myself on track

It runs in about as many seconds as the hours it took to create:
Simulation of area filling with oxygen

To my delight, it was the correct answer!

  • I'm so glad I used the alphabet and named my frames to match the number of minutes I was on

I did it!!!

  • I solved both parts!
  • I created my most complex GIF thus far in the series...and thankfully got the correct answer out of the tedious exercise!
  • I built an interactive robot-maze-traversing simulator that helped me reveal the full maze, including the location of the oxygen system
  • I've now completed 7/7 Intcode puzzles
  • I've now built 7 Intcode computer simulators

The goal is always to solve, not necessarily with an algorithm.

And in my opinion, building a game is always a great way to solve these puzzles!

Top comments (0)