10001th prime: Difference between revisions

→‎{{header|Picat}}: Forgot the essential predicates.
(→‎{{header|Picat}}: Forgot the essential predicates.)
Line 454:
% faster but probably considered cheating
nth(10001,primes(200000),P),
println(P).</lang>
 
nth_prime(Choosen) = P =>
nth_prime(1,0,Choosen, P).
 
nth_prime(Num, Choosen, Choosen, Num) :-
prime(Num).
nth_prime(Num, Ix, Choosen, P) :-
Ix < Choosen,
next_prime(Num, P2),
nth_prime(P2, Ix+1, Choosen, P).
 
next_prime(Num, P) :-
next_prime2(Num+1, P).
next_prime2(Num, Num) :-
prime(Num).
next_prime2(Num, P) :-
next_prime2(Num+1,P).</lang>
 
{{out}}
495

edits