Module day16

Source
Expand description

ยงThe Floor Will Be Lava

Brute force solution tracing the path of each beam, changing direction or splitting according to the rules of each tile.

To speed things up the next coordinate in each direction is precomputed for every point so that the empty spaces between mirrros and splitters are filled efficiently.

Some beams can enter a closed loop so we keep track of previously seen (position, direction) pairs and stop if weโ€™ve seen a pair before.

For part two each path is independent so we can use multiple threads in parallel to speed up the search.

Structsยง

Input
Shared ๐Ÿ”’
Atomics can be safely shared between threads.

Constantsยง

DOWN ๐Ÿ”’
LEFT ๐Ÿ”’
RIGHT ๐Ÿ”’
UP ๐Ÿ”’

Functionsยง

count ๐Ÿ”’
Count the number of energized tiles from a single starting location.
parse
Build four precomputed grids of the next coordinate in each direction for every point.
part1
part2
worker ๐Ÿ”’
Process starting locations from a shared queue.

Type Aliasesยง

Pair ๐Ÿ”’