Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Anagrams By Stacks solution in Uncategorized category for Anagrams By Stacks by capback250
maxL = 0
def checkio(data):
global maxL
inputStack, result = data.split('-')
maxL = len(result)
states, res, curr = [], [], []
queue = []
queue.append([inputStack, '', '', ''])
while queue:
state = queue.pop()
states.append(state[:-1])
path = state[3]
if state[2] == result:
res = state[-1]
break
moves = possibleMoves(state)
for move in moves:
if move[:-1] not in states and move[:-1] not in curr:
curr.append(move[:-1])
queue.insert(0, move[:-1]+[path + move[-1]])
maxL = 0
return ','.join(filter(bool, res.split(',')))
def possibleMoves(params):
inSt, buff, ouSt, path = params
moves = []
if inSt and not buff:
moves.append([inSt[:-1], inSt[-1], ouSt, '10,'])
if inSt and len(ouSt) < maxL:
moves.append([inSt[:-1], buff, ouSt+inSt[-1], '12,'])
if len(inSt) < maxL and buff:
moves.append([inSt + buff, '', ouSt, '01,'])
if len(ouSt) < maxL and buff:
moves.append([inSt, '', ouSt + buff, '02,'])
if len(inSt) < maxL and ouSt:
moves.append([inSt + ouSt[-1], buff, ouSt[:-1], '21,'])
if ouSt and not buff:
moves.append([inSt, ouSt[-1], ouSt[:-1], '20,'])
return moves
Feb. 11, 2016