Day 11 part 2 done.
Went a bit to an
Overthinking Land.
My initial strategy was to build a map of all recurring stones (during 75 blinks) that map to a list of their derivatives. In the test dataset there were 76 unique keys after 36 blinks that did not increase anymore till 75th blink. So I had a hope there without actually knowing exactly what I'm going to do with them yet, but was thinking along the lines, that will traverse the map like a tree later, going to key, then each of its children (derivatives), back to key, its children again... and as you imagine, that didn't get me anywhere.
Then had a dinner, took the dog (Beagle) out for a walk, re-read instructions once again, and thought, hang on, instructions say:
"No matter how the stones change, their order is preserved...", and thought, what's the story about the order being preserved, that's an unnecessary restriction - that doesn't matter at all!
OKEY, that's a typical divide-and-conquer problem from now onwards. So started thinking how to run through subsets of stones 75 blinks each and later just add their counts. Now, don't tell anyone, but one moment was considering to write a
Spark job crunching stuff in parallel and persisting intermediate results to a disk so don't occupy memory when don't need to. Then in the case of success of course was thinking, how I'm gonna tell you guys this brain fart
After thinking more, did no more than what you'd expect a Day 11 actually could bring given we are not even half way through - a simple Map with counts of each stone at a given moment, so it doesn't grow as a list would.
FACEPALM