domains
Ilist = Integer*
predicates
take(Integer,Integer,Ilist)
del(Ilist,integer,Ilist)
min(Ilist,integer)
minN(Ilist,integer,Ilist,Ilist)
goal
minN([1,-2,3,-7,-8,4],3,L,M),
take(3,X,L),write(X).
clauses
del([H|Tail],H,Tail):-!.
del([H|Tail],X,[H|NewTail]):-del(Tail,X,NewTail).
min([H],H).
min([H|Tail],H):-min(Tail,M),H<M,!.
min([_|Tail],M):-min(Tail,M).
minN([],_,[],[]):-!.
minN(L,0,L,[]):-!.
minN(L,N,AnsList,[M|MTail]):-min(L,M), del(L,M,L1),
N1 = N-1, minN(L1,N1,AnsList,MTail).
take(1,X,[X|_]):-!.
take(I,X,[_|L]):-I1=I-1,!,take(I1,X,L). |