This is an Advent of Code solution. Click to reveal!
The cogs are turning...