A surprisingly easy puzzle, considering it’s day 22! Part 1 is extremely straightforward. Part 2 required a few moments’ thought. If you store all the bids, you’re looking at a very large array, and a naive brute-force search (heh, not that BFS, the bad BFS!) strikes me as probably infeasible. So I defined a 4-dimensional array, each indixed over the range -9…9, and while doing Part 1 stored each monkey’s first price to generate a 4-number sequence in the array. Worked like a charm! though a bit slow. My only holdup was my desire for certainty, and misreading some diagnostic output in Part 2 made me doubt that I had the right algorithm, when in fact I did. Pro tip: When searching for a sequence of numbers such as 3, -1, 1, -2
, editors will also detect -3, -1, 1, -2
. Be smart enough not to confuse the two.
1 Like