We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1615cf0 + 44c3c16 commit 31d397fCopy full SHA for 31d397f
1 file changed
DSA 450 GFG/tower_of_hanoi.py
@@ -0,0 +1,9 @@
1
+# we have to transfer n disks from rod A to C using the auxilliary rod B
2
+def tower_of_hanoi(n, A, B, C):
3
+ if(n>0):
4
+ tower_of_hanoi(n-1, A, C, B)
5
+ print("Moving disk ",n," from rod ", A, " to rod ", C)
6
+ tower_of_hanoi(n-1, B, A, C)
7
+
8
+n= int(input())
9
+tower_of_hanoi(n, 'A','B','C')
0 commit comments