Algorithm/BOJ 기초
[백준] 하노이 탑 이동 순서 11729 Python (재귀)
hackyu
2019. 10. 12. 16:56
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
cnt = 0
result = []
def hanoi(n, fromm, by, to):
global cnt
cnt += 1
if n == 1:
else:
hanoi(n-1, fromm, to, by)
hanoi(n-1, by, fromm, to)
n = int(input())
hanoi(n,1,2,3)
print(cnt)
for i in result:
print(i)
|
|