For today's puzzle, we are playing tetris.
We'll represent the state of our world with the following little object. Our rock
is a set of coordinates that we will manipulate, our fixed
are all of the squares that have already frozen in place. We'll keep track of the set of all rocks
that we will cycle through, indexed by rock-num
, as well as the move-str
of all of the moves we'll cycle through, our current location being move-num
. time
will denote how many blocks have fallen, and top
is the heighest y
coordinate in fixed.
We'll build a nice image renderer so that we can see the game board.
To start we'll implement the basic components we need to get some blocks moving.
We already have what we need in place to solve the first part.
If we have any hope of doing a huge number of steps, we are going to have to prune our fixed set to only have a single spot at each height. We only need to keep those blocks that are 'visible' from the very top, at which point we can sort of shift our whole state down again to be nestled at the origin, after doing that we'll store a hidden
parameter that says how much height we've just eaten up.
By normalizing our states like this, we should be able to easily detect if there is a cycle in the states.
If we detect a cycle we can do a fast warp into the future to get near to our eventual goal.
We'll then just run ordinarily until we hit it, in case there are residual steps needed.