Last active
April 28, 2021 12:34
-
-
Save costa86/6e3407132e5c77ce8d6a80b581c2102a to your computer and use it in GitHub Desktop.
Solves Hanoi Tower puzzle
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
#print moves | |
def move(disc,origin,destination): | |
print('Disc',disc,'from tower',origin,'to tower',destination) | |
count = 1 | |
def hanoi(n,fr,to,temp): | |
'''print moves on hanoi tower puzzle | |
Args: | |
n(int):number of discs | |
fr(string):origin tower | |
to(str):destination tower | |
temp(str):temporary tower''' | |
global count | |
if n > 0: | |
hanoi(n-1,fr,temp,to) | |
print(f'Moviment {count}:') | |
move(n,fr,to) | |
count+=1 | |
hanoi(n-1,temp,to,fr) | |
hanoi(3,'a','c','b') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment