Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short solution in Clear category for Mind Switcher by StefanPochmann
def mind_switcher(journal):
has = {}
for a, b in journal:
has[a], has[b] = has.get(b, b), has.get(a, a)
swaps, n, s, odd = [], 'nikola', 'sophia', 0
while has:
a, b = has.popitem()
if a != b:
swaps += [{a, n}, {b, s}, {n, b}]
while b != a:
b = has.pop(b)
swaps += [{s, b}]
odd ^= 1
return swaps + [{n, s}] * odd
April 28, 2015
Comments: