Module day15

Source
Expand description

§Rambunctious Recitation

For efficiency the vec storing the last previously spoken turn of numbers is u32. Each difference is at least one so zero is used as a special value to indicate numbers not seen before.

To speed things up even more, we notice that most large numbers over a certain threshold are spoken only once. Storing if numbers have been seen before in a compact bitset prevents expensive reads to main memory and halves the time needed for the solution.

Zero occurs the most so storing it as a dedicated variable saves another 2% of execution time.

Constants§

THRESHOLD 🔒

Functions§

parse
part1
part2
play 🔒