We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f2addcc commit fdf4febCopy full SHA for fdf4feb
1 file changed
이티준희/11729_하노이탑.py
@@ -0,0 +1,55 @@
1
+#2023-04-27-Week3
2
+#11729_하노이 탑.py
3
+
4
5
+'''
6
+하노이탑 원판 1개인 경우 -> top(1, 1, 2, 3)
7
+이동 과정
8
+1. 1번 1->3
9
10
+하노이탑 원판 2개인 경우 -> top(2, 1, 2, 3)
11
12
+1. 1번 1->2
13
+2. 2번 1->3
14
+3. 1번 2->3
15
16
+하노이탑 원판 3개인 경우 -> top(3, 1, 2, 3)
17
18
19
+2. 2번 1->2
20
+3. 1번 3->2
21
+4. 3번 1->3
22
+5. 1번 2->1
23
+6. 2번 2->3
24
+7. 1번 1->3
25
26
27
28
+n = int(input())
29
30
+def cnt(n) :
31
+ if n==1 :
32
+ k = 2
33
+ elif n<=0 :
34
+ k = 1
35
+ else :
36
+ k = 2*cnt(n-1)
37
+ return k
38
39
+def top(n, a, b, c) :
40
41
+ print(a,c)
42
43
+ #else 코드는 스스로 작성하지 못함
44
+ top(n-1,a,c,b)
45
46
+ top(n-1,b,a,c)
47
48
49
+함수 쓰지 않고 바로 계산해도 됨
50
+sum = 2**n-1
51
+print(sum)
52
53
+print(cnt(n))
54
+top(n, 1, 2, 3)
55
0 commit comments