Created
June 29, 2017 02:54
-
-
Save a-eid/60f9f38d6d33fb80cae650c89cd77852 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Tower of Hanoi """ | |
def printMove(fr , to): | |
print("move from {} to {} ".format(str(fr),str(to)) ) | |
def towers(num , original , dist ,spare): | |
if num == 1: | |
printMove(original , dist) | |
else: | |
towers(num-1, original , spare , dist) # move the upper stack to spare to | |
towers(1, original , dist , spare) # move the bigger to to | |
towers(num-1 , spare , dist , original) # move the upper back to to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment