Task

Solve the   Towers of Hanoi   problem with recursion.




define hanoi use ndisks, startpeg, endpeg
   ndisks 0 > if
      6 startpeg - endpeg - startpeg ndisks 1 - hanoi
      endpeg startpeg ndisks "Move disk %d from peg %d to peg %d\n" print 
      endpeg 6 startpeg - endpeg - ndisks 1 - hanoi
 
define dohanoi use ndisks
   # startpeg=1, endpeg=3
   3 1 ndisks hanoi
 
# 4 disks
4 dohanoi
 