Advertisement
manish

Untitled

Jan 8th, 2023
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. queue = [[1, 2, 3, 4, 5]]
  2.  
  3. path = {str(queue[0]): []}
  4.  
  5. while queue:
  6.     x = queue.pop(0)
  7.     for i in range(1, 6):
  8.         y = x[:i][::-1] + x[i:]
  9.         for j in range(i):
  10.             y[j] = y[j] - 5 if y[j] > 5 else y[j] + 5
  11.         if str(y) not in path:
  12.             path[str(y)] = path[str(x)] + [i]
  13.             queue += [y]
  14. print(path[str([5, 4, 3, 2, 1])])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement