Sum of two adjacent numbers are primes: Difference between revisions

Added Action!
(Added PL/M)
(Added Action!)
Line 7:
Show the ten millionth such prime sum.
<br>
 
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<syntaxhighlight lang="action!">
;;; Find numbers n such that n + n+1 is prime
;;; Library: Action! Sieve of Eratosthenes
INCLUDE "H6:SIEVE.ACT"
 
PROC PrintC2( CARD n )
IF n < 10 THEN Put(' ) FI
PrintC( n )
RETURN
 
PROC Main()
DEFINE MAX_PRIME = "255"
 
BYTE ARRAY primes(MAX_PRIME)
CARD n, n1, count
Sieve(primes,MAX_PRIME)
 
count = 0;
n1 = 1
WHILE count < 20 DO
n = n1
n1 ==+ 1
IF primes( n + n1 ) THEN
count ==+ 1
PrintC2( count )
Print( ": " )
PrintC2( n )
Print( " + " )
PrintC2( n1 )
Print( " = " )
PrintC2( n + n1 )
PutE()
FI
OD
 
RETURN
</syntaxhighlight>
{{out}}
<pre>
1: 1 + 2 = 3
2: 2 + 3 = 5
3: 3 + 4 = 7
4: 5 + 6 = 11
5: 6 + 7 = 13
6: 8 + 9 = 17
7: 9 + 10 = 19
8: 11 + 12 = 23
9: 14 + 15 = 29
10: 15 + 16 = 31
11: 18 + 19 = 37
12: 20 + 21 = 41
13: 21 + 22 = 43
14: 23 + 24 = 47
15: 26 + 27 = 53
16: 29 + 30 = 59
17: 30 + 31 = 61
18: 33 + 34 = 67
19: 35 + 36 = 71
20: 36 + 37 = 73
</pre>
 
=={{header|ALGOL 68}}==
Line 46 ⟶ 110:
36 + 37 = 73
</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
3,043

edits