Successive prime differences: Difference between revisions

(Realize in F#)
Line 427:
(4 2) has 1444 sets: 7 11 13 … 997807 997811 997813
(6 4 2) has 306 sets: 31 37 41 43 … 997141 997147 997151 997153</pre>
 
=={{header|Phix}}==
Uses primes[] and add_block() from [[Extensible_prime_generator#Phix|Extensible_prime_generator]]
<lang Phix>procedure test(sequence differences)
sequence res = {}
integer ld = length(differences)
for i=1 to length(primes)-ld do
integer pi = primes[i]
for j=1 to ld do
pi += differences[j]
if pi!=primes[i+j] then
pi = 0
exit
end if
end for
if pi!=0 then
res = append(res,primes[i..i+ld])
end if
end for
res = {differences,length(res),res[1],res[$]}
printf(1,"%8v : %8d %14v...%v\n",res)
end procedure
 
while length(primes)<1_000_000 do add_block() end while
primes = primes[1..abs(binary_search(1_000_000,primes))-1]
constant differences = {{2},{1},{2,2},{2,4},{4,2},{6,4,2}}
printf(1,"Differences Count First Last\n")
for i=1 to length(differences) do test(differences[i]) end for</lang>
{{out}}
<pre>
Differences Count First Last
{2} : 8169 {3,5}...{999959,999961}
{1} : 1 {2,3}...{2,3}
{2,2} : 1 {3,5,7}...{3,5,7}
{2,4} : 1393 {5,7,11}...{999431,999433,999437}
{4,2} : 1444 {7,11,13}...{997807,997811,997813}
{6,4,2} : 306 {31,37,41,43}...{997141,997147,997151,997153}
</pre>
 
=={{header|Python}}==
7,820

edits