Double Twin Primes: Difference between revisions

Content added Content deleted
Line 483: Line 483:
=={{header|Ring}}==
=={{header|Ring}}==
<syntaxhighlight lang="ring">
<syntaxhighlight lang="ring">
see "works..." + nl
see "working..." + nl
primes = []
P = []

limit = 1000
limit = 1000
for n =1 to limit
for n =1 to limit
if isPrime(n)
if isP(n)
add(primes,n)
add(P,n)
ok
ok
next
next
lenPrimes = len(primes)-3
lenP = len(P)-3
for m = 1 to lenPrimes
for m = 1 to lenP
if isPrime(primes[m]) and isPrime(primes[m+1]) and
if isP(P[m]) AND isP(P[m+1]) AND isP(P[m+2]) AND isP(P[m+3])
isPrime(primes[m+2]) and isPrime(primes[m+3])
if (P[m+1] - P[m] = 2) AND (P[m+2] - P[m+1] = 4) AND (P[m+3] - P[m+2] = 2)
if (primes[m+1] - primes[m] = 2) and (primes[m+2] - primes[m+1] = 4) and
see " " + P[m]+ " " + P[m+1] + " " +
(primes[m+3] - primes[m+2] = 2)
P[m+2] + " " + P[m+3] + nl
see " " + primes[m]+ " " + primes[m+1] + " " +
primes[m+2] + " " + primes[m+3] + nl
ok
ok
ok
ok
next
next

see "done..." + nl
see "done..." + nl


func isPrime num
func isP num
if (num <= 1) return 0 ok
if (num <= 1) return 0 ok
if (num % 2 = 0 and num != 2) return 0 ok
if (num % 2 = 0 AND num != 2) return 0 ok
for i = 3 to floor(num / 2) -1 step 2
for i = 3 to floor(num / 2) -1 step 2
if (num % i = 0) return 0 ok
if (num % i = 0) return 0 ok
next
next
return 1
return 1
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}