Primes whose sum of digits is 25: Difference between revisions

→‎{{header|ALGOL 68}}: Use ALGOL 68-prime
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:
=={{header|ALGOL 68}}==
<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 #
PR read "primes.incl.a68" PR
INT max show sum25 = 4999;
[]BOOL prime = eratosthenes(PRIMESIEVE max show sum25 )4999;
INT p25 count := 0;
FOR n TO maxUPB show sum25prime DO
IF prime[ n ] THEN
# have a prime, check for a sum25 prime #
Line 47 ⟶ 35:
FI
OD;
print( ( newline, "Found ", whole( p25 count, 0 ), " sum25 primes below ", whole( maxUPB show sum25prime + 1, 0 ), newline ) )
END</lang>
{{out}}
Line 114 ⟶ 102:
END</lang>
{{out}}
Note that ALGOL 68G under Windows is fully interpreted so runtime is not of the same order as the Phix and Go samples,. underUnder Linux with optimisation and compilation., it mayshould be faster than under Windows.
<pre>
There are 1525141 sum25 primes that contain no zeroes
3,043

edits