Search code examples
cperformancetowers-of-hanoi

Optimal C implementation of the Towers of Hanoi puzzle with k pegs


How do you solve the Towers of Hanoi puzzle when there are k pegs? Can it be done in an optimal way in C? Is there a greedy algorithm for it?


Solution

  • See this github page for the code in C: https://github.com/kcolford/hanoi/blob/master/src/hanoi.c

    See this page to know why it's minimal: http://kcolford.com/the-towers-of-hanoi-2/