/* Generate primes in Picat. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go ?=> gen(P), println(P), fail. go => true. go2 ?=> gen(P), println(P), (P >= 10000 ; fail). go2 => true. % Another approach using member/2 go3 ?=> member(P, [I : I in 2..10000, prime(I)]), println(P), fail. go3 => true. % Generate primes gen(N) => next_prime(2,N). % Num is a prime next_prime(Num, P), prime(Num) ?=> P = Num. % step to next prime next_prime(Num, P) ?=> (Num <= 2 -> Num2 = Num + 1 ; Num2 = Num + 2 ), next_prime(Num2,P).