Skip to content

Commit

Permalink
#14 : 11729_하노이 탑
Browse files Browse the repository at this point in the history
  • Loading branch information
devCharlotte committed Apr 27, 2023
1 parent f2addcc commit fdf4feb
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions 이티준희/11729_하노이탑.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#2023-04-27-Week3
#11729_하노이 탑.py


'''
하노이탑 원판 1개인 경우 -> top(1, 1, 2, 3)
이동 과정
1. 1번 1->3
하노이탑 원판 2개인 경우 -> top(2, 1, 2, 3)
이동 과정
1. 1번 1->2
2. 2번 1->3
3. 1번 2->3
하노이탑 원판 3개인 경우 -> top(3, 1, 2, 3)
이동 과정
1. 1번 1->3
2. 2번 1->2
3. 1번 3->2
4. 3번 1->3
5. 1번 2->1
6. 2번 2->3
7. 1번 1->3
'''

n = int(input())

def cnt(n) :
if n==1 :
k = 2
elif n<=0 :
k = 1
else :
k = 2*cnt(n-1)
return k

def top(n, a, b, c) :
if n==1 :
print(a,c)
else :
#else 코드는 스스로 작성하지 못함
top(n-1,a,c,b)
print(a,c)
top(n-1,b,a,c)

'''
함수 쓰지 않고 바로 계산해도 됨
sum = 2**n-1
print(sum)
'''
print(cnt(n))
top(n, 1, 2, 3)

0 comments on commit fdf4feb

Please sign in to comment.