Primes whose sum of digits is 25: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added the displaying of a foot separtor, added/changed comments, added whitespace, optimized the main DO loop.)
(→‎{{header|ALGOL 68}}: Use ALGOL 68-prime)
Line 15: Line 15:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find primes whose digits sum to 25 #
<lang algol68>BEGIN # find primes whose digits sum to 25 #
# returns a sieve of primes up to n #
PROC eratosthenes = ( INT n )[]BOOL:
BEGIN
[ 1 : n ]BOOL p;
p[ 1 ] := FALSE; p[ 2 ] := TRUE;
FOR i FROM 3 BY 2 TO n DO p[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO n DO p[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( n ) DO
IF p[ i ] THEN FOR c FROM i * i BY i + i TO n DO p[ c ] := FALSE OD FI
OD;
p
END # eratosthenes # ;
# show all sum25 primes below 5000 #
# show all sum25 primes below 5000 #
PR read "primes.incl.a68" PR
INT max show sum25 = 4999;
[]BOOL prime = eratosthenes( max show sum25 );
[]BOOL prime = PRIMESIEVE 4999;
INT p25 count := 0;
INT p25 count := 0;
FOR n TO max show sum25 DO
FOR n TO UPB prime DO
IF prime[ n ] THEN
IF prime[ n ] THEN
# have a prime, check for a sum25 prime #
# have a prime, check for a sum25 prime #
Line 47: Line 35:
FI
FI
OD;
OD;
print( ( newline, "Found ", whole( p25 count, 0 ), " sum25 primes below ", whole( max show sum25 + 1, 0 ), newline ) )
print( ( newline, "Found ", whole( p25 count, 0 ), " sum25 primes below ", whole( UPB prime + 1, 0 ), newline ) )
END</lang>
END</lang>
{{out}}
{{out}}
Line 114: Line 102:
END</lang>
END</lang>
{{out}}
{{out}}
Note that ALGOL 68G under Windows is fully interpreted so runtime is not of the same order as the Phix and Go samples, under Linux with optimisation and compilation. it may be faster.
Note that ALGOL 68G under Windows is fully interpreted so runtime is not of the same order as the Phix and Go samples. Under Linux with optimisation and compilation, it should be faster than under Windows.
<pre>
<pre>
There are 1525141 sum25 primes that contain no zeroes
There are 1525141 sum25 primes that contain no zeroes