Home [Python] 백준 11729번 : 하노이 탑 이동 순서
Post
Cancel

[Python] 백준 11729번 : 하노이 탑 이동 순서

Problem

https://www.acmicpc.net/problem/11729

Solution

code

1
2
3
4
5
6
7
8
9
10
11
12
def hanoi(n, before, after) :
    if n == 1 :
        print(before, after)
        return
       
    hanoi(n-1, before, 6-before-after) # 1단계
    print(before, after) # 2단계
    hanoi(n-1, 6-before-after, after) # 3단계
    
n = int(input())
print(2**n - 1)
hanoi(n, 1, 3)

Ref.

https://study-all-night.tistory.com/6

This post is licensed under CC BY 4.0 by the author.

[Python] 백준 1009번 : 분산처리

[C언어] 다양한 포인터