cnt = 0
def hanoimove(num, fromm, by, to):
global cnt
cnt += 1
if num == 1:
#print("%d이 %c에서 %c로 이동 " % (num, fromm, to))
print("%c -> %c" % (fromm, to))
else:
hanoimove(num-1, fromm, to, by)
#print("%d이 %c에서 %c로 이동 " % (num, fromm, to))
print("%c -> %c" % (fromm, to))
hanoimove(num-1, by, fromm, to)
hanoimove(4,'A','B','C')
print(cnt)
|
'Algorithm' 카테고리의 다른 글
[정렬] 삽입정렬 (0) | 2019.10.12 |
---|---|
[정렬] 선택정렬 (Select Sort) (0) | 2019.10.11 |
[정렬] 버블정렬 (Bubble Sort) (0) | 2019.10.11 |
이진탐색(binary search) (0) | 2019.09.25 |
[Algorithm] 01. 이진 검색 알고리즘 테스트 Binary Search Algorithm Test (python) (0) | 2018.08.25 |