Module day18

Source
Expand description

§Like a Rogue

We represent a trap with a 1 bit and a safe tile with a 0 bit. Writing out the truth table for the rules:

LeftCenterRightOutput
1101
0111
1001
0011
1110
0100
1010
0000

We can see that the value of the center doesn’t matter and that the next tile will be a trap if the left and right values are different. We calculate this for all traps at the same time with a bitwise XOR.

Since even columns depend only on odd columns and vice-versa, we split the input into two, storing each half using 50 bits of a u64.

Functions§

count 🔒
parse
part1
part2