Skip to content

Commit f63e6de

Browse files
committed
1 parent 007a0cc commit f63e6de

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Hongjoo/lv2/히노이의탑.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
- 작은 수가 위로 올라감
3+
조건
4+
1. 한번에 한개만 옮기기 가능
5+
2, 큰원판 은 아래 , 작은 원판은 위
6+
3. 기둥 3개
7+
# 재귀
8+
goal : 기둥 1 -> 기둥 3으로 옮기는 방법 최소 방법
9+
#flow
10+
1. (n-1)개 원판 start => 중앙 (재귀) 몰아 넣기
11+
2. n 번째 원판 : start -> target 이동
12+
3. (n-1) 개 원판 중앙 -> target (재귀) 몰아 넣기
13+
14+
15+
"""
16+
answer = []
17+
def hannoi(src ,target , inter , n) :
18+
if n== 1 :
19+
answer.append([src, target])
20+
else :
21+
hannoi(src , inter , target , n-1)
22+
hannoi(src, target , inter , 1)
23+
hannoi(inter, target, src , n-1)
24+
25+
def solution(n):
26+
27+
hannoi(1 ,3 , 2 , n)
28+
29+
return answer

0 commit comments

Comments
 (0)