Successive prime differences: Difference between revisions

(add FreeBASIC)
Line 2,176:
last group: 997141 997147 997151 997153
count: 306
</pre>
 
=={{header|Ring}}==
<lang ring>
load "stdlib.ring"
see "working..." + nl + nl
see "For primes less than 1,000,000:" + nl + nl
num = 0
limit = 1000000
Primes = []
SuccPrimes = []
Sp = [[2],[1],[2,2],[2,4],[4,2],[6,4,2]]
 
for n = 1 to limit
if isprime(n)
add(Primes,n)
ok
next
 
for n = 1 to len(Sp)
num = 0
for m = 1 to len(Primes)-len(Sp[n])
flag = 0
SuccPrimes = []
for p = 1 to len(Sp[n])
if (Primes[m+p]-Primes[m+p-1] = Sp[n][p])
flag++
add(SuccPrimes,Primes[m+p])
add(SuccPrimes,Primes[m+p-1])
else
exit
ok
next
 
SuccPrimes = sort(SuccPrimes)
for x = len(SuccPrimes) to 2 step -1
if SuccPrimes[x] = SuccPrimes[x-1]
del(SuccPrimes,x)
ok
next
 
if len(SuccPrimes) = len(Sp[n])+1
num++
LastSuccPrimes = SuccPrimes
if num = 1
see "For differences of "
showArray(Sp[n])
see " ->" + nl
see " First group = "
showArray(SuccPrimes)
see nl
ok
ok
next
see " Last group = "
showArray(LastSuccPrimes)
see nl
see " Number found = " + num + nl + nl
next
 
see "done..." + nl
 
func showArray(array)
txt = ""
see "["
for n = 1 to len(array)
txt = txt + array[n] + ","
next
txt = left(txt,len(txt)-1)
txt = txt + "]"
see txt
</lang>
{{out}}
<pre>
working...
 
For primes less than 1,000,000:
 
For differences of [2] ->
First group = [3,5]
Last group = [999959,999961]
Number found = 8169
 
For differences of [1] ->
First group = [2,3]
Last group = [2,3]
Number found = 1
 
For differences of [2,2] ->
First group = [3,5,7]
Last group = [3,5,7]
Number found = 1
 
For differences of [2,4] ->
First group = [5,7,11]
Last group = [999431,999433,999437]
Number found = 1393
 
For differences of [4,2] ->
First group = [7,11,13]
Last group = [997807,997811,997813]
Number found = 1444
 
For differences of [6,4,2] ->
First group = [31,37,41,43]
Last group = [997141,997147,997151,997153]
Number found = 306
 
done...
</pre>
 
2,468

edits