mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-21 16:52:05 +00:00
Tower of Hanoi
This commit is contained in:
parent
cf295c39de
commit
8d5be8a436
33
Tower_of_Hanoi.py
Normal file
33
Tower_of_Hanoi.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
F=[];
|
||||
U=[];
|
||||
T=[];
|
||||
|
||||
def show():
|
||||
print "\n\nF : ", F;
|
||||
|
||||
print "U : ", U;
|
||||
|
||||
print "T : ", T;
|
||||
|
||||
|
||||
def mov(From, To):
|
||||
To.append(From.pop());
|
||||
|
||||
def TOH(n, From, Using, To):
|
||||
if n==1:
|
||||
mov(From, To);
|
||||
show();
|
||||
else:
|
||||
TOH(n-1, From, To, Using);
|
||||
mov(From, To);
|
||||
show();
|
||||
TOH(n-1, Using, From, To);
|
||||
|
||||
n=input("Enter The Height of Hanoi Tower : ");
|
||||
F=range(n,0,-1);
|
||||
show();
|
||||
|
||||
TOH(n, F, U, T);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user