Expand description
§Pyroclastic Flow
§Part One
For speed we encode each rock shape as binary bits so that we can use bitwise logic to check for collisions. Each rock is encoded top to bottom and left to right. For example:
# 00010000 0x10
### => 00111000 => 0x38 => 0x00103810
# 00010000 0x10
The bits are shifted 2 away from the left wall. Walls are also encoded in binary, overlapping the left and right walls (no rock will ever collide first with a wall and its top row):
100000001
100000001 => 0x01010101
100000001
We store the accumulated tower efficiently as a vec of u8
including the floor at index
zero as a special pattern of 11111111
.
We use bitwise AND to check for collisions between the rock, the walls and the existing tower in one operation.
§Part Two
Since there’s no reasonable way to analytically predict the height after some n
rocks
and brute force would take too long we can assume that there must be a
cycle in the output.
We choose an arbitrary length and generate a sequence of that size then search
for repeating patterns. Once we find the length of the cycle then we can extrapolate for
any n
greater than the start of the cycle.
Structs§
Constants§
- FLOOR 🔒Encode pieces one row per byte, highest row in the most significant position.
- ROCKS 🔒
- WALLS 🔒
Functions§
Type Aliases§
- Wrapper 🔒Convenience alias to shorten type name.