Mind Switcher Mind Switcher
English FR RU

- Oh no! Is it possible to get everyone back to normal using four or more bodies?

- I'm not sure. I'm afraid we need to use... MATH.

"Futurama" - Season 6 Episode 10 - "The Prisoner of Benda"

Sophia's drones are simple robots which do dangerous work. Just in case one breaks, Sophia has a backup machine for these drones. This machine can copy a robots mind and has a secret and undocumented function. The backup machine can also operate as a mind switcher for robots.

Sophia forgot to turn off the machine and left the drones in the same room. When she had returned some drones already swapped their minds with each other. We should help them to return to their original bodies as their current state voids the manufacturer warranty.

We have a log from the machine, of which drones minds were swapped. There is however one slight problem - no pair of bodies can swap minds more than once. However, with two additional bodies we can return the switching chaos back to a normal state of things. Nikola and Sophia have offered to help us ("nikola" and "sophia").

You are given an array with with information about the recent swaps. Each entry is a set with two names of robots (bodies). You can operate with bodies which were written in the journal and with two additional bodies - "nikola" and "sophia". Find the sequence of the swaps required to return all minds to their original bodies. The result should be represented as a list/tuple of sets with two names in each.

Input: A journal as a tuple of sets. Each set contains two strings.

Output: The sequence of actions as a list/tuple of sets. Each set contains two strings.


mind_switcher(({"scout", "super"},)) == ({"super", "nikola"}, {"sophia", "scout"},
                                         {"nikola", "scout"}, {"sophia", "super"},
                                         {"nikola", "sophia"})


How it is used: The theorem from this mission is based on group theory. And group theory has application in cryptography, physics and chemistry.

0 < len(journal) ≤ 55
Journal is correct.

Sources: Cohen, David (2010). Futurama volume 5 DVD episode 10 "The Prisoner of Benda" (DVD). 20th Century Fox.