Twin primes: Difference between revisions

Added XPL0 example.
(added J solution)
(Added XPL0 example.)
Line 1,715:
</pre>
 
=={{header|XPL0}}==
100 million takes 150 seconds on Pi4.
<lang XPL0>func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
func Twins(Limit);
int Limit, C, N;
[C:= 0; N:= 3;
repeat if IsPrime(N) then
loop [N:= N+2;
if N >= Limit then return C;
if not IsPrime(N) then quit;
C:= C+1;
];
N:= N+2;
until N >= Limit;
return C;
];
 
[IntOut(0, Twins(100_000)); CrLf(0);
IntOut(0, Twins(10_000_000)); CrLf(0);
IntOut(0, Twins(100_000_000)); CrLf(0);
]</lang>
 
{{out}}
<pre>
1224
58980
440312
</pre>
 
=={{header|Yabasic}}==
772

edits