Successive prime differences: Difference between revisions

Content added Content deleted
Line 261: Line 261:
Last group = [997141 997147 997151 997153]
Last group = [997141 997147 997151 997153]
Number found = 306
Number found = 306
</pre>

=={{header|J}}==
<pre>
primes_less_than=: i.&.:(p:inv)
assert 2 3 5 -: primes_less_than 7

PRIMES=: primes_less_than 1e6


NB. Insert minus `-/' into the length two infixes `\'.
NB. Passive `~' swaps the arguments producing the positive differences.
SUCCESSIVE_DIFFERENCES=: 2 -~/\ PRIMES

assert 8169 -: +/ 2 = SUCCESSIVE_DIFFERENCES NB. twin prime tally


INTERVALS=: 2 ; 1 ; 2 2 ; 2 4 ; 4 2 ; 6 4 2

sequence_index=: [: I. E.
end_groups=: PRIMES {~ ({. , {:)@:] +/ i.@:>:@:#@:[

HEAD=: <;._2 'group;tally;end occurrences;'

HEAD , INTERVALS (([ ([ ; #@] ; end_groups) sequence_index)~ >)"1 0~ SUCCESSIVE_DIFFERENCES
┌─────┬─────┬───────────────────────────┐
│group│tally│end occurrences │
├─────┼─────┼───────────────────────────┤
│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>
</pre>