After fixing your save file, you are ready to play the video game - Maze Master.
However, your cat has decided to join the fun and started spamming random buttons on your controller, making you get lost in the maze very soon after.
Luckily, the game records your past moves and display them on the side bar (your puzzle input), ordered from oldest to newest, which you can use to work out your position.
In the beginning, you are located at the entrance of the maze.
There are two basic moves in this game: >
and <
.
>
moves you towards the right by 1
space.<
moves you towards the left by 1
space.There are also two advanced moves in this game: >>
and <<
. You still haven't worked out what they do, but it seems that they work as follows:
>>
moves you towards the right by 5
spaces.<<
moves you towards the left by 5
spaces.To figure out your location, you need to calculate the distance from the entrance by simulating the moves.
Consider the following example, taking right as positive:
Current position
start | 0
> | 1
<< | -4
< | -5
>> | 0
> | 1
< | 0
<< | -5
<< | -10
> | -9
>> | -4
> | -3
The distance from the entrance is 3
, taking the absolute value.
After executing your moves, what is your distance from the entrance?
You head back to the entrance. Strangely, the entrance isn't there when you reach it.
After checking the manual, you realize a couple of things.
Firstly, there are multiple layers to this maze.
Secondly, you have misunderstood what the advanced moves does:
>>
moves you upward by 1
layer.<<
moves you downward by 1
layer.Finally, each layer is 1000
spaces apart from its neighbouring layers.
You still need to calculate the distance from the entrance. The distance can be obtained by multiplying your vertical position by 1000
, then adding it to your horizontal position.
Consider the example above, taking right and upward as positive:
Horizontal position Vertical position
start | 0 | 0
> | 1 | 0
<< | 1 | -1
< | 0 | -1
>> | 0 | 0
> | 1 | 0
< | 0 | 0
<< | 0 | -1
<< | 0 | -2
> | 1 | -2
>> | 1 | -1
> | 2 | -1
Taking the absolute value, the actual distance from the entrance is 1 x 1000 + 2 = 1002
.
Execute your moves again. What is your actual distance from the entrance?