You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
400 B

% Prolog version of a Prime Number Finder
% haplo@mindstab.net
check(I,C,M,P) :-
P \= 0,
I > M.
check(I,C,M,P) :-
P \= 0,
NP is C mod I,
NI is I + 2,
check(NI,C,M,NP).
primes(M) :-
nl, primes(3,M,2).
primes(C,M,S) :- C > M.
primes(C,M,S) :-
check(3,C,S,1),
write(C), nl,
NC is C + 2,
NS is sqrt(NC),
primes(NC,M,NS).
primes(C,M,S) :-
NC is C + 2,
NS is sqrt(NC),
primes(NC,M,NS).