Skip to content

Commit 00a9824

Browse files
committed
[BOJ] #1914. 하노이의탑 / 실버1 / 50분 / 성공
1 parent 025f991 commit 00a9824

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 하노이 함수
2+
def hanoi_f(one, three, n):
3+
if n == 1:
4+
print(one, three)
5+
return
6+
7+
hanoi_f(one, 6 - one - three, n - 1) # 1단계 (1->2)
8+
print(one, three) # 2단계 (마지막원반 1->3)
9+
hanoi_f(6 - one - three, three, n - 1) # 3단계 (2->3)
10+
11+
12+
# 메인
13+
n = int(input())
14+
print(2 ** n - 1)
15+
if n <= 20:
16+
hanoi_f(1, 3, n)

0 commit comments

Comments
 (0)