Special neighbor primes: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Use the new prime list routines in Algol 68-primes) |
|||
Line 10: | Line 10: | ||
{{libheader|ALGOL 68-primes}} |
{{libheader|ALGOL 68-primes}} |
||
<lang algol68>BEGIN # find adjacent primes p1, p2 such that p1 + p2 - 1 is also prime # |
<lang algol68>BEGIN # find adjacent primes p1, p2 such that p1 + p2 - 1 is also prime # |
||
INT max prime = 100; |
|||
# sieve the primes to max prime * 2 # |
|||
PR read "primes.incl.a68" PR |
PR read "primes.incl.a68" PR |
||
INT max prime = 100; |
|||
# |
[]BOOL prime = PRIMESIEVE ( max prime * 2 ); # sieve the primes to max prime * 2 # |
||
INT |
[]INT low prime = EXTRACTPRIMESUPTO max prime FROMPRIMESIEVE prime; # construct a list of the primes up to max prime # |
||
# construct a list of the primes up to max prime # |
|||
[ 1 : p count ]INT low prime; |
|||
INT low pos := 0; |
|||
FOR i WHILE low pos < UPB low prime DO IF prime[ i ] THEN low prime[ low pos +:= 1 ] := i FI OD; |
|||
# find the adjacent primes p1, p2 such that p1 + p2 - 1 is prime # |
# find the adjacent primes p1, p2 such that p1 + p2 - 1 is prime # |
||
FOR i TO UPB low prime - 1 DO |
FOR i TO UPB low prime - 1 DO |