-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanoi_tower.py
19 lines (15 loc) · 863 Bytes
/
hanoi_tower.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def Hanoi_tower(n,source,destination,aux):
if n==1:
#agar faghat ye disk dashte bashim ba enteghal be destination tamoome!!
print('Move disk 1 from source',source,'to destination',destination)
return
#in mige ke be komake mile destination n-1 disk e ma montaghel beshan be
# mile aux;yani func ke var migire destination esh mishe hamoon mile aux!
Hanoi_tower(n-1,source,aux,destination)
# inja mige ke hame disk ha ke montaghel shodan be aux akharin disk
# ke hamoon n om bashe montaghel mishe be destination e ma
print('Move disk',n,'from source',source,'to destination',destination)
#bad az inke akharin disk(disk n om) raft be destination,disk haye roo
# aux be komake mile source va avalie montaghel beshan be destination!!!
Hanoi_tower(n-1,aux,destination,source)
Hanoi_tower(4,'A','C','B')