Metadata
-
Date
-
Tagged
-
Part of series
- Advent of Code 2024 Day 1
- Advent of Code 2024 Day 2
- Advent of Code 2024 Day 3
- Advent of Code 2024 Day 4
- Advent of Code 2024 Day 5
- Advent of Code 2024 Day 6
- Advent of Code 2024 Day 7
- Advent of Code 2024 Day 8
- Advent of Code 2024 Day 9
- Advent of Code 2024 Day 10
- Advent of Code 2024 Day 11
- Advent of Code 2024 Day 12
- Advent of Code 2024 Day 13
- Advent of Code 2024 Day 14
- Advent of Code 2024 Day 15
- Advent of Code 2024 Day 16
- Advent of Code 2024 Day 17
- Advent of Code 2024 Day 18
- Advent of Code 2024 Day 19
- Advent of Code 2024 Day 20
-
Older post
-
Newer post
Advent of Code 2024 Day 14
Day 14: Restroom Redoubt
https://adventofcode.com/2024/day/14
Another day, another familiar location.
You are in the lobby of Easter Bunny HQ. There are a bunch of robots running around.
Today’s input is a list of all robots, it lists:
- Their initial position
- The change to their position each time they move.
An example input looks like this:
Each line represents 1 robot, the position and velocity are 2 number pairs. A robot only ever moves along a straight line, in other words, each step it takes, add the velocity to its position.
- The first number is the column index
- The second number is the row index
The area the robots move in is:
- 101 tiles wide
- 103 tiles tall
The robots have a special property, they wrap around the area they move in. That means:
- if they go off the top, they continue from the bottom
- if they go off the bottom, they continue from the top
- if they go off the left, they continue from the right
- if they go off the right, they continue from the left For an example, the problem description has a good one.
Parsing
If you’ve been following along, you know what I do when I see a puzzle with coordinates by now, Point
!
And today, I expanded that with a Robot
struct.
You guessed it, that holds TWO Point
s.
Data structures
Turning the input into a list of Robot
s:
Part 1
The question asks for the safety score after 100 steps.
To calculate a safety score for an arrangement of robots, count the amount of bots in each quadrant. Robots that are in the exact middle row or column don’t count towards the safety score.
The safety score is the product of the amount of robots in each quadrant.
Helpers
A function that takes in a list of robots, and calculates the safety score. Paying attention to the global values for the amount of rows and columns in the area.
Code
Move the robots 100 steps and calculate the safety score. Because of a math property, I didn’t loop 100 times and moved each robot once per step. I moved them 100 steps at once.
Part 2
The robots have an easter egg, at some point, they form a christms tree.
There are many ways to verify this, the most straightforward, and the one I initially did, is to print out the arrangement of robots repeatedly.
With the help of others, it turn out that the first time all robots occupy a unique position is the iteration the christmas tree is shown.
So I looped infinitely and broke the loop the first time no 2 robots occupy the same location.