Double Twin Primes: Difference between revisions

J
(J)
Line 398:
[ 821 823 827 829]
</pre>
 
=={{header|J}}==
<syntaxhighlight lang=J> _6 _4 0 2+/~(#~ 0,4=2-~/\])p:~.,0 1+/~/I.2=2 -~/\ i.&.(p:inv) 1000
5 7 11 13
11 13 17 19
101 103 107 109
191 193 197 199
821 823 827 829</syntaxhighlight>
 
Breaking this down:
 
<syntaxhighlight lang=J> primes=: i.&.(p:inv) 1000
twinprimes=: p:~.,0 1+/~/I.2=2 -~/\ primes
doubletwinprimes=: _6 _4 0 2+/~(#~ 0,4=2-~/\])</syntaxhighlight>
 
The first two expressions rely on the primitive <code>p:</code> which translates between the index of a prime number and the prime itself. The final expression instead filters the remaining primes (because the sequence of primes which was its argument had already been filtered enough to have made indices into that sequence into relevant information which was not worth recalculating).
 
=={{header|Julia}}==
6,951

edits