Module aoc::year2015::day04

source ·
Expand description

§The Ideal Stocking Stuffer

This solution relies on brute forcing combinations as quickly as possible using an internal implementation of the MD5 hashing algorithm.

Each number’s hash is independent of the others, so we speed things up by using threading to search in parallel in blocks of 1000 numbers at a time.

Using the format! macro to join the secret key to the number is quite slow. To go faster we reuse the same u8 buffer, incrementing digits one at a time. The numbers from 1 to 999 are handled specially.

Interestingly the total time to solve this problem is extremely sensitive to the secret key provided as input. For example my key required ~10⁷ iterations to find the answer to part two. However for unit testing, I was able to randomly find a value that takes only 455 iterations, about 22,000 times faster!

Structs§

Functions§