Jump to content

Strange unique prime triplets: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 85:
 
If n, m, p < 1000 finds 241580
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"
 
PROC Main()
DEFINE MAXPRIME="29"
DEFINE MAX="99"
BYTE ARRAY primes(MAX+1)
BYTE n,m,p,c
INT count=[0]
 
Put(125) PutE() ;clear the screen
Sieve(primes,MAX+1)
c=0
FOR n=2 TO MAXPRIME-2
DO
IF primes(n) THEN
FOR m=n+1 TO MAXPRIME-1
DO
IF primes(m) THEN
FOR p=m+1 TO MAXPRIME
DO
IF primes(p)=1 AND primes(n+m+p)=1 THEN
PrintF("%I+%I+%I=%I ",n,m,p,n+m+p)
count==+1 c==+1
IF c=3 THEN
c=0 PutE()
FI
FI
OD
FI
OD
FI
OD
PrintF("%EThere are %I prime triplets",count)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strange_unique_prime_triplets.png Screenshot from Atari 8-bit computer]
<pre>
3+5+11=19 3+5+23=31 3+5+29=37
3+7+13=23 3+7+19=29 3+11+17=31
3+11+23=37 3+11+29=43 3+17+23=43
5+7+11=23 5+7+17=29 5+7+19=31
5+7+29=41 5+11+13=29 5+13+19=37
5+13+23=41 5+13+29=47 5+17+19=41
5+19+23=47 5+19+29=53 7+11+13=31
7+11+19=37 7+11+23=41 7+11+29=47
7+13+17=37 7+13+23=43 7+17+19=43
7+17+23=47 7+17+29=53 7+23+29=59
11+13+17=41 11+13+19=43 11+13+23=47
11+13+29=53 11+17+19=47 11+19+23=53
11+19+29=59 13+17+23=53 13+17+29=59
13+19+29=61 17+19+23=59 19+23+29=71
 
There are 42 prime triplets
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.