Advertisement
EmiMancilha

hanoi

Nov 17th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. #torre de hanoi
  2. #função de qual movimento fazer
  3. def mover(po, pd):
  4. print(f"{po:d} - {pd:d}") #qual movimento devemos fazer
  5. def hanoi(np, po, pd, pt):
  6. if (np>0):
  7. hanoi(np -1, po, pt, pd)
  8. mover(po, pd)
  9. hanoi(np -1, pt, pd, po)
  10. else:
  11. return
  12. #programa
  13. n = int(input("Numero de pinos: "))
  14. hanoi(n,1,3,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement