Jump to content

[PYTHON] Tower of Hanoi


AdeM nWo
 Share

Recommended Posts

Tower of Hanoi


Description: A small function that helps solving the Tower of Hanoi Game by telling which moves to do


Photos / Video: Capture d'écran 2025-01-06 180256.png


Download link:

 

def hanoi(n,A,B,C):
	if n>0:
		hanoi(n-1,A,C,B)
		print(A,"-->",B)
		hanoi(n-1,C,B,A)
		
n=int(input("Number of Disk: "))
hanoi(n,"A","B","C")

#-------------------------------------------
# n = Number of Disks
# Where A represents Tower 1(Left one)
# Where B represents Tower 2(Middle one)
# Where C represents Tower 3(Right one)

Source (optional): -
Other mentions: Click here to play the Tower of Hanoi 

 

 

Edited by AdeM nWo
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.