Double Twin Primes: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(→{{header|ALGOL 68}}: Replaced with simpler version not based on the successive prime differences task) |
||
Line 20: | Line 20: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Reusing some code from the [[Successive prime differences#ALGOL_68|Successive prime differences task]]. |
|||
{{libheader|ALGOL 68-primes}} |
{{libheader|ALGOL 68-primes}} |
||
{{libheader|ALGOL 68-rows}} |
|||
<syntaxhighlight lang="algol68"> |
<syntaxhighlight lang="algol68"> |
||
BEGIN # find some sequences of primes where the gaps between the elements # |
BEGIN # find some sequences of primes where the gaps between the elements # |
||
# are 2, 4, 2 - i.e., n, n+2, n+6 and n+8 are all prime # |
# are 2, 4, 2 - i.e., n, n+2, n+6 and n+8 are all prime # |
||
PR read "primes.incl.a68" PR # include prime utilities # |
PR read "primes.incl.a68" PR # include prime utilities # |
||
[]BOOL prime = PRIMESIEVE 1 000; |
|||
PR read "rows.incl.a68" PR # include row (array) utilities # |
|||
⚫ | |||
# attempts to find patterns in the differences of primes and prints the results # |
|||
FOR p FROM LWB prime TO UPB prime - 8 DO |
|||
PROC try differences = ( []INT primes, []INT pattern, INT max prime )VOID: |
|||
IF prime[ p ] THEN |
|||
IF prime[ p + 2 ] THEN |
|||
IF prime[ p + 6 ] THEN |
|||
IF prime[ p + 8 ] THEN |
|||
count +:= 1; |
|||
print( ( "[" |
|||
, whole( p, -4 ), whole( p + 2, -4 ) |
|||
, whole( p + 6, -4 ), whole( p + 8, -4 ) |
|||
, " ]" |
|||
, newline |
|||
) |
|||
) |
|||
FI |
|||
IF matched THEN |
|||
# found a matching sequence # |
|||
⚫ | |||
print( ( "[" ) ); |
|||
SHOW primes[ p - pattern length : p ]; |
|||
print( ( " ]", newline ) ) |
|||
FI |
FI |
||
FI |
|||
FI |
|||
print( ( "Found ", whole( count, 0 ), " prime sequences with differences: [" ) ); |
|||
OD; |
|||
SHOW pattern; |
|||
print( ( "Found ", whole( count, 0 ), " double twin primes beflow ", whole( UPB prime, 0 ), newline ) ) |
|||
print( ( newline ) ) |
|||
END # try differences # ; |
|||
INT max number = 1 000; |
|||
[]INT p list = EXTRACTPRIMESUPTO max number FROMPRIMESIEVE PRIMESIEVE max number; |
|||
try differences( p list, ( 2, 4, 2 ), max number ) |
|||
END |
END |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
[ 5 7 11 13 ] |
[ 5 7 11 13 ] |
||
[ 11 13 17 19 ] |
[ 11 13 17 19 ] |
||
[ 101 103 107 109 ] |
[ 101 103 107 109 ] |
||
[ 191 193 197 199 ] |
[ 191 193 197 199 ] |
||
[ 821 823 827 829 ] |
[ 821 823 827 829 ] |
||
Found 5 |
Found 5 double twin primes beflow 1000 |
||
</pre> |
</pre> |
||