Hanoi top

2024. 7. 21. 23:12Algorithm

list1 = [5,4,3,2,1] 
def pm(start,end):
    print(f"{start} ---> {end}") 
def hanoi(n,start,end):
    if n == 1:
        pm(start,end) 
    else:
        other = 6 - start - end 
        hanoi(n-1,start,other)
        pm(start,end)
        hanoi(n-1,other,end)
hanoi(3,1,3)

'Algorithm' 카테고리의 다른 글

[Leetcode]342. Power of Four  (3) 2024.07.22
[Leetcode]203. Remove Linked List Elements  (0) 2024.07.22
[Leetcode]234. Palindrome Linked List  (0) 2024.07.21
[Leetcode]21. Merge Two Sorted Lists  (2) 2024.07.20
[Leetcode]509. Fibonacci Number  (0) 2024.07.19