Figured out that the center position did not matter,
as long as left hand side tile and right hand side
tile on previous row are not equal.
Also tried to find a recurring pattern to speed
p2 up a bit, but it seems it does not have a
recurring pattern in the 400 000s first rows.
Lost 60 minutes due to misinterpreting this in p2:
> *whenever* you generate a hash
The code initially only did the 2016 stretching for
the triplet hash, not the quintet hash. By doing it
to both, pt 2 is solved.
Not sure the lru cache actually speeds anything up.
Many on the subreddit used the approach to generate
the quintet first and look backwards 1000 times
for a matching quintet (since quintets are more
rare than triplets), this will most likely speed
things up.
Also, this solution do not store the found keys.
Many other solutions do, I believe this is some
presumptions.
Hard one, an infamous AoC puzzle according to
Reddit.
Apparently, this is a classic logic problem named
"Missionaries and cannibals", or "Jealous husbands".
Hard lessons:
- Always use set() for visited nodes during BFS.
- Always use collections.queue() to create to queue
traversals for BFS.
- itertools permutations(), combinations() and
pairwise() may look similar, but they are not.
- Learned to use (?:chunk of text)? in regex.
Test data was achieved without bigger hazzles, but
to optimize code required a lot of Reddit browsing
and code reading from blogs. I have mentioned the
sources in a doc string.