Skip to content

Instantly share code, notes, and snippets.

@costa86
Last active April 28, 2021 12:34
Show Gist options
  • Save costa86/6e3407132e5c77ce8d6a80b581c2102a to your computer and use it in GitHub Desktop.
Save costa86/6e3407132e5c77ce8d6a80b581c2102a to your computer and use it in GitHub Desktop.
Solves Hanoi Tower puzzle
#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