CalmoSoft primes: Difference between revisions

→‎Stretch: It's faster using Miller-Rabin...
(→‎{{header|ALGOL 68}}: Fixed </pre>)
(→‎Stretch: It's faster using Miller-Rabin...)
Line 77:
===Stretch===
Basically the same algorithm as the Algol 68 Basic task sample.
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<br>Runs in around two seconds when transpiled to VB.NET using an experimental/WIP/toy transpiler.
Uses Algol 68G's LONG LONG INT for the Millar Rabin test.
<br>To run it with Algol 68G version 2, you need <code>-heap 512M</code> on the command line.
<br>TookTo overrun a minutethis with Algol 68G onversion the2, Windowsyou 11need system<code>-heap 512M</code> on the I'mcommand usingline.
<br>Took about 30 seconds with Algol 68G on the Windows 11 system I'm using, 40-45 seconds on TIO.RUN.
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">
BEGIN # find the longest sequence of primes < 50 000 000 that sums to a prime#
# called Calmosoft primes #
PR read "primes.incl.a68" PR
# returns TRUE if n is prime, FALSE otherwise - uses trial division #
PROC is prime = ( LONG INT n )BOOL:
IF n < 3 THEN n = 2
ELIF n MOD 3 = 0 THEN n = 3
ELIF NOT ODD n THEN FALSE
ELSE
BOOL is a prime := TRUE;
FOR f FROM 5 BY 2 WHILE LENG f * LENG f <= n AND ( is a prime := n MOD f /= 0 )
DO SKIP OD;
is a prime
FI # is prime # ;
INT max prime = 50 000 000;
[ 0 : max prime ]BOOL prime;
Line 128 ⟶ 120:
WHILE IF this end < this start OR this len < max len
THEN FALSE
ELSE NOT ( this prime := is probably prime( this sum ) )
FI
DO
3,044

edits