primes.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:08.0
disk size 489 Bytes
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
%query: primes(i,o).

% From "Programming in Prolog" by Clocksin and Mellish, 1981

primes(Limit, Ps) :- integers(2, Limit, Is), sift(Is, Ps).

integers(Low, High, [Low|Rest]) :-
    Low =< High, !, M is Low+1, integers(M, High, Rest).
integers(_, _, []).

sift([], []).
sift([I|Is],[I|Ps]) :- remove(I, Is, New), sift(New, Ps).

remove(P, [], []).
remove(P, [I|Is], [I|Nis]):-
    \+ 0 is I mod P,
    !, remove(P, Is, Nis).
remove(P, [I|Is], Nis) :- 0 is I mod P, !, remove(P, Is, Nis).
popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark