Double Twin Primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: technically these are) |
(Added XPL0 example.) |
||
Line 64: | Line 64: | ||
821 823 827 829 |
821 823 827 829 |
||
done... |
done... |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if odd N is prime |
|||
int N, D; |
|||
[for D:= 3 to sqrt(N) do |
|||
[if rem(N/D) = 0 then return false; |
|||
D:= D+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
int N; |
|||
[N:= 3; |
|||
repeat if IsPrime(N) then |
|||
if IsPrime(N+2) then |
|||
if IsPrime(N+6) then |
|||
if IsPrime(N+8) then |
|||
[IntOut(0, N); ChOut(0, ^ ); |
|||
IntOut(0, N+2); ChOut(0, ^ ); |
|||
IntOut(0, N+6); ChOut(0, ^ ); |
|||
IntOut(0, N+8); CrLf(0); |
|||
]; |
|||
N:= N+2; |
|||
until N >= 1000-8; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
5 7 11 13 |
|||
11 13 17 19 |
|||
101 103 107 109 |
|||
191 193 197 199 |
|||
821 823 827 829 |
|||
</pre> |
</pre> |
Revision as of 16:36, 24 March 2023
Definition
Let (p1,p2) and (p3,p4) be twin primes where p3 - p2 = 4.
Such primes called Double Twin Primes
Example
[5,7,11,13]
Task
Find and show here all Double Twin Primes under 1000.
Raku
Cousin twin primes:
sub dt { $^p, $p+2, $p+6, $p+8 }
.&dt.say for (^1000).grep: { all .&dt».is-prime };
- Output:
(5 7 11 13) (11 13 17 19) (101 103 107 109) (191 193 197 199) (821 823 827 829)
Ring
see "works..." + nl
primes = []
limit = 1000
for n =1 to limit
if isPrime(n)
add(primes,n)
ok
next
lenPrimes = len(primes)-3
for m = 1 to lenPrimes
if isPrime(primes[m]) and isPrime(primes[m+1]) and
isPrime(primes[m+2]) and isPrime(primes[m+3])
if (primes[m+1] - primes[m] = 2) and (primes[m+2] - primes[m+1] = 4) and
(primes[m+3] - primes[m+2] = 2)
see " " + primes[m]+ " " + primes[m+1] + " " +
primes[m+2] + " " + primes[m+3] + nl
ok
ok
next
see "done..." + nl
func isPrime num
if (num <= 1) return 0 ok
if (num % 2 = 0 and num != 2) return 0 ok
for i = 3 to floor(num / 2) -1 step 2
if (num % i = 0) return 0 ok
next
return 1
- Output:
works... 5 7 11 13 11 13 17 19 101 103 107 109 191 193 197 199 821 823 827 829 done...
XPL0
func IsPrime(N); \Return 'true' if odd N is prime
int N, D;
[for D:= 3 to sqrt(N) do
[if rem(N/D) = 0 then return false;
D:= D+1;
];
return true;
];
int N;
[N:= 3;
repeat if IsPrime(N) then
if IsPrime(N+2) then
if IsPrime(N+6) then
if IsPrime(N+8) then
[IntOut(0, N); ChOut(0, ^ );
IntOut(0, N+2); ChOut(0, ^ );
IntOut(0, N+6); ChOut(0, ^ );
IntOut(0, N+8); CrLf(0);
];
N:= N+2;
until N >= 1000-8;
]
- Output:
5 7 11 13 11 13 17 19 101 103 107 109 191 193 197 199 821 823 827 829