Advertisement
MaxDvc

Hanoi

Dec 21st, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. def hanoi(n,A,C,B):
  2. #@param:
  3. #   n: int, number of rings;
  4. #   A: str, initial pole;
  5. #   C: str, destination pole;
  6. #   B: str, empty pole;
  7.     if n==1:
  8.         print("Move ring from",A,"to",C)
  9.     else:
  10.         hanoi(n-1,A,B,C)
  11.         print("Move ring from",A,"to",C)
  12.         hanoi(n-1,B,C,A)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement