Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Mind Switcher by flpo
def mind_switcher(journal):
s, res, odd, N, S = {}, [], 0, 'nikola', 'sophia'
for x, y in journal:
s[x], s[y] = s.get(y, y), s.get(x, x)
s = {k: v for k, v in s.items() if k != v}
while s:
c = list(s.popitem())
while c[-1] in s and s[c[-1]] != c[0]:
c.append(s.pop(c[-1]))
del s[c[-1]]
res += [{N, c[-1]}] + [{S, b} for b in c] + [{N, c[0]}]
odd ^= 1
return res + [{N, S}] * odd
Aug. 29, 2017
Comments: