Skip to content

Commit cb42aac

Browse files
authored
implt hanoi test (#2)
1 parent dea9684 commit cb42aac

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

04-functions-modules/guide.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77

88
Implement `min`, `max` functions on your own.
99

10+
11+
## Hanoi
12+
- difficulty: ★☆☆
13+
- time: ~ 30m for beginners
14+
- background: recursion
15+
16+
Implement `hanoi` function on your own. `hanoi` function is a guide that tells how to move disks in tower based on certain rules. You can find specific information about "Tower of Hanoi" in here [[wiki](https://en.wikipedia.org/wiki/Tower_of_Hanoi, "hanoitowerwiki")].
17+
1018
## Binomial Coefficient
1119

1220
- difficulty: ★★☆
1321
- time: ~ 30m for beginners
1422
- background: function, recursion
1523

1624
Implement a function which calculates binomial coefficient, $\prescript{}{n}C_k$.
25+

04-functions-modules/hanoi.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
def hanoi(n, src, dest, aux):
2+
"""
3+
>>> hanoi(1, "A", "C", "B")
4+
Move disk 1 from A to C
5+
>>> hanoi(3, "A", "C", "B")
6+
Move disk 1 from A to C
7+
Move disk 2 from A to B
8+
Move disk 1 from C to B
9+
Move disk 3 from A to C
10+
Move disk 1 from B to A
11+
Move disk 2 from B to C
12+
Move disk 1 from A to C
13+
>>> hanoi(5, "A", "C", "B")
14+
Move disk 1 from A to C
15+
Move disk 2 from A to B
16+
Move disk 1 from C to B
17+
Move disk 3 from A to C
18+
Move disk 1 from B to A
19+
Move disk 2 from B to C
20+
Move disk 1 from A to C
21+
Move disk 4 from A to B
22+
Move disk 1 from C to B
23+
Move disk 2 from C to A
24+
Move disk 1 from B to A
25+
Move disk 3 from C to B
26+
Move disk 1 from A to C
27+
Move disk 2 from A to B
28+
Move disk 1 from C to B
29+
Move disk 5 from A to C
30+
Move disk 1 from B to A
31+
Move disk 2 from B to C
32+
Move disk 1 from A to C
33+
Move disk 3 from B to A
34+
Move disk 1 from C to B
35+
Move disk 2 from C to A
36+
Move disk 1 from B to A
37+
Move disk 4 from B to C
38+
Move disk 1 from A to C
39+
Move disk 2 from A to B
40+
Move disk 1 from C to B
41+
Move disk 3 from A to C
42+
Move disk 1 from B to A
43+
Move disk 2 from B to C
44+
Move disk 1 from A to C
45+
"""
46+
# TODO
47+
48+
if __name__ == "__main__":
49+
import doctest
50+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)