AoC# 2024 - Day 14: Restroom Redoubt

2 minute read

It’s Advent of Code time 🎄

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill levels that can be solved in any programming language you like.

We’ve already dodged guards this year, and on Day 14 we’re avoiding security robots!

Part 1 ⭐️

Straightforward enough, once I’d fixed a couple of off-by-1 errors: I’d taken the tile space as given but used zero-indexing for the robot positions; and teleporting with a negative velocity to a position less than zero needed to account for zero being a space/move.

Part 2 ⭐️

An unexpected twist…

credit: fit_femboy_

But how’s this for a vague requirement:

most of the robots should arrange themselves into a picture of a Christmas tree.

What is the fewest number of seconds that must elapse for the robots to display the Easter egg?

What, exactly, are we looking for?! No hint of where in the space or what size this tree could be1 meant that my first thought was to compare the left half of the space mirrored the right2, but the “most of the robots” gave me doubt this would work.

My next thought was to eyeball the output… it was easy to create a simple console output map of the robot’s locations but it was hard to track, so I switched to rendering ~10,0003 images as they’d be easier to page through in the Finder:

image of a folder full of image thumbnails, one of which has a small box containing a christmas tree in it

Ahhh! That's what we're looking for!

I wasn’t the only one with this idea 😄

credit: piman51277

  1. There wasn’t a hint about trees in the previous year’s puzzle referenced in the introduction; it concerns keypad entry codes. 

  2. Not a bad thought, given Part 1 has us counting robots in quadrants. 

  3. 10,000 was chosen at random. I figured I could just keep generating blocks of images if need be. Turns out my answer was in the first block. 

Updated: