Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
From Chalk Board solution in Clear category for Mind Switcher by bryukh
def mind_switcher(journal):
state = {}
for r1, r2 in journal:
state[r1], state[r2] = state.get(r2, r2), state.get(r1, r1)
#clear state - remove "correct" drones
state = {b: m for b, m in state.items() if b != m}
names = list(state.keys())
ring_groups = []
current = None
while names:
if not current:
current = names.pop()
current_group = []
ring_groups.append(current_group)
else:
names.remove(current)
current_group.append(current)
next_name = state[current]
current = None if next_name in current_group else next_name
path = []
y = 'nikola'
x = 'sophia'
for ring in ring_groups:
k = len(ring)
for i in range(k - 1):
path.append({x, ring[i]})
path.append({y, ring[k - 1]})
path.append({x, ring[k - 1]})
path.append({y, ring[0]})
if len(ring_groups) % 2:
path.append({y, x})
return path
July 23, 2014
Comments: