Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
18 lines solution in Clear category for Mind Switcher by freeman_lex
def mind_switcher(j):
bots, chains, log = {}, [], []
for bot1, bot2 in j:
bots[bot1], bots[bot2] = bots.get(bot2, bot2), bots.get(bot1, bot1)
bots = [(k, v) for k, v in bots.items() if k != v]
while bots:
chains += [bots.pop()]
i = chains[-1]
while i[0] != i[-1]:
for s, e in bots:
if s == i[-1]:
i += e,
bots.remove((s, e))
log += set(('nikola', i[0])), set(('sophia', i[-2])), set(('sophia', i[0]))
log += [set(('nikola', j)) for j in i[1:-1]]
if len(chains) % 2:
log += set(('nikola', 'sophia')),
return log
July 7, 2016
Comments: