def hanoi(n, from_pos, to_pos, aux_pos):
if n == 1:
print(from_pos,'->',to_pos)
return
hanoi(n-1, from_pos, aux_pos, to_pos)
print(from_pos, '->', to_pos) #출력; 원반을 옮기는 순서
hanoi(n-1, aux_pos, to_pos, from_pos)
hanoi(3,1,3,2)
'Coding Test > Python' 카테고리의 다른 글
[python] 최소공배수, 최대공약수, 유클리드 호제법 (0) | 2023.04.12 |
---|---|
[Python] 약자 만들기.py (0) | 2021.10.05 |
[Python] 소수이자 피보나치 넘버.py (0) | 2021.10.05 |
[Python] map 함수 (0) | 2021.09.06 |
[Python] 탐색 find_pos.py (0) | 2021.09.06 |