1 parent 52d2fbf commit b2f1d9cCopy full SHA for b2f1d9c
1 file changed
maths/Hanoi.py
@@ -0,0 +1,24 @@
1
+# @author willx75
2
+# Tower of Hanoi recursion game algorithm is a game, it consists of three rods and a number of disks of different sizes, which can slide onto any rod
3
+
4
+import logging
5
6
+log = logging.getLogger()
7
+logging.basicConfig(level=logging.DEBUG)
8
9
10
+def Tower_Of_Hanoi(n, source, dest, by, mouvement):
11
+ if n == 0:
12
+ return n
13
+ elif n == 1:
14
+ mouvement += 1
15
+ # no print statement (you could make it an optional flag for printing logs)
16
+ logging.debug('Move the plate from', source, 'to', dest)
17
+ return mouvement
18
+ else:
19
20
+ mouvement = mouvement + Tower_Of_Hanoi(n-1, source, by, dest, 0)
21
22
23
+ mouvement = mouvement + 1 + Tower_Of_Hanoi(n-1, by, dest, source, 0)
24
0 commit comments