Guest User

Untitled

a guest
Apr 10th, 2020
358
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. valid = []
  2.  
  3.  
  4. def find(target, stack, depth=10, sequance=''):
  5.     if stack == target:
  6.         valid.append(sequance)
  7.         return
  8.     if depth <= 0:
  9.         return
  10.     t_stack = stack[:]
  11.     t = stack[-1]
  12.     del t_stack[-1]
  13.     t_stack.insert(-2, t)
  14.     find(target, t_stack, depth - 1, sequance + 't')
  15.     s_stack = stack[:]
  16.     t = stack[-1]
  17.     del s_stack[-1]
  18.     s_stack.insert(-1, t)
  19.     find(target, s_stack, depth - 1, sequance + 's')
  20.     d_stack = stack[:]
  21.     d_stack.append(stack[-1])
  22.     find(target, d_stack, depth - 1, sequance + 'd')
  23.  
  24.  
  25. find(['c','b','a'][::-1], ['a', 'b', 'c'][::-1])
  26. print(min(valid, key=len))
RAW Paste Data