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.