home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part01 / fproot / demo / Hanoi < prev    next >
Encoding:
Text File  |  1987-07-05  |  422 b   |  23 lines

  1. (*
  2.  * Hanio - towers of Hanoi solver
  3.  *
  4.  * <N Names> : Hanoi -> <<src dst> ...<src dst>>
  5.  *
  6.  * where N is number of rings and names is a triple of post names
  7.  * <source temporary dest>.
  8.  *
  9.  * Example:
  10.  *    <2 <a b c>> : Hanoi -> <<a,b>,<a,c>,<b,c>>
  11.  *)
  12.  
  13. DEF Hanoi AS
  14.    {[n,[a,b,c]] := id}
  15.    IF [n,#0]|= THEN []
  16.    ELSE [
  17.       [n|sub1, [a,c,b]] | Hanoi,
  18.       [[a,c]],
  19.       [n|sub1, [b,a,c]] | Hanoi 
  20.    ] | cat
  21.    END;
  22.  
  23.