Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short BFS solution in Creative category for Anagrams By Stacks by StefanPochmann
def checkio(data):
start, goal = data.split('-')
queue, seen = [({'1':start, '0':'', '2':''}, '')], set()
for s, moves in queue:
for i, j, k in '012 021 102 120 201 210'.split():
if s[i] and (j>'0' or not s[j]):
t = {i:s[i][:-1], j:s[j]+s[i][-1], k:s[k]}
key = frozenset(t.items())
if key not in seen:
if t['2'] == goal:
return moves+i+j
queue.append((t, moves+i+j+','))
seen.add(key)
April 20, 2015