Module day06

Source
Expand description

ยงMemory Reallocation

Looking at the input and the reallocation rules, we make an assertion:

  • No memory bank will ever exceed 15 blocks.

This has a nice effect that we can store the entire memory layout packed into a single u64 with each memory bank represented by a nibble.

This makes it very fast to find the highest nibble using bitwise logic. To detect the cycle a FastMap stores each previously seen memory layout along with the cycle that it first appeared.

Constantsยง

REMOVE ๐Ÿ”’
Reallocate a bank and set to zero by rotating this mask the correct number of bits.
SPREAD ๐Ÿ”’
The highest number of banks possible is 15, so each bank will add at most 1 to each of the banks that come after it.

Functionsยง

parse
part1
part2

Type Aliasesยง

Input ๐Ÿ”’