Friday, May 21, 2010

Towers of hanoi

Psuedo code for towers of hanoi algorithm.

def Hanoi(n, A, C, B):
    if n != 0:
        // Transfer n-1 plates from A to B.
        Hanoi(n - 1, A, B, C)
        print 'Move the plate ', n, ' from ', A, ' to ', C
        // Now transfer n-1 plates from B to C.
        Hanoi(n - 1, B, C, A) 

No comments:

Post a Comment