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 >
Wrap
Text File
|
1996-06-04
|
428b
|
27 lines
hanoi(1,A,B,C,[[A,B]]).
hanoi(N,A,B,C,Ms:ensuite(Ms1,[[A,B]|Ms2])) :-
N>1=true,
hanoi(N-1,A,C,B,Ms1),
hanoi(N-1,C,B,A,Ms2),
% 15.9 Because asserta is now nonstrict:
MMs=Ms, asserta(hanoi(N,A,B,C,MMs) :- !),
write('Solved problem for N=',N),
nl.
ensuite([],A:list)
-> A.
ensuite([H|T],M)
-> [H|ensuite(T,M)].
test(N:int) :-
hanoi(N,A,B,C,M),
write('Solution:'),
nl,
write(M).
dynamic(hanoi)?