VikkaLorel

hanoiResolution

May 28th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. def fillA(n, a):
  2.     while n > 0:
  3.         a.append(n)
  4.         n = n - 1
  5.     return (a)
  6.  
  7.  
  8. def smove(a, b):
  9.     global i
  10.     if len(a) > 0:
  11.         b.append(a.pop())
  12.         print(source, C, target)
  13.         i = i + 1
  14.  
  15.  
  16. def move(n, start, end, auxiliary):
  17.     if n == 1:
  18.         smove(start, end)
  19.     if n > 1:
  20.         move(n - 1, start, auxiliary, end)
  21.         smove(start, end)
  22.         move(n - 1, auxiliary, end, start)
  23.  
  24. if __name__ == '__main__':
  25.     x = int(input("Nombre de palet :"), 10)
  26.     i = 0
  27.     source = list()
  28.     target = list()
  29.     C = list()
  30.     source = fillA(x, source)
  31.     print("Positions de départ : ", source, C, target)
  32.     move(x, source, target, C)
  33.     print("Etapes : ", i)
Add Comment
Please, Sign In to add comment