Programming
2020. 6. 22.
[알고리즘] 하노이 탑(recursion)
Function def move_disk(disk_num, start_peg, end_peg): print("%d번 원판을 %d번 기둥에서 %d번 기둥으로 이동" % (disk_num, start_peg, end_peg)) def hanoi(num_disks, start_peg, end_peg): if num_disks == 1: return move_disk(num_disks,start_peg,end_peg) other_peg = 6 - start_peg - end_peg hanoi(num_disks-1,start_peg,other_peg) move_disk(num_disks,start_peg,end_peg) hanoi(num_disks-1,other_peg,end_peg) Test Algorithm ..