home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / HANOI.LF < prev    next >
Text File  |  1996-06-04  |  428b  |  27 lines

  1. hanoi(1,A,B,C,[[A,B]]).
  2.  
  3.  
  4. hanoi(N,A,B,C,Ms:ensuite(Ms1,[[A,B]|Ms2])) :-
  5.         N>1=true,
  6.         hanoi(N-1,A,C,B,Ms1),
  7.         hanoi(N-1,C,B,A,Ms2),
  8.         % 15.9 Because asserta is now nonstrict:
  9.         MMs=Ms, asserta(hanoi(N,A,B,C,MMs) :- !),
  10.         write('Solved problem for N=',N),
  11.         nl.
  12.  
  13.  
  14. ensuite([],A:list)     
  15.         -> A.
  16. ensuite([H|T],M)     
  17.         -> [H|ensuite(T,M)].
  18.  
  19. test(N:int) :-
  20.         hanoi(N,A,B,C,M),
  21.         write('Solution:'),
  22.         nl,
  23.         write(M).
  24.  
  25. dynamic(hanoi)?
  26.  
  27.