Sexy primes: Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎{{header|J}}: brute force approach)
Line 1,137: Line 1,137:


=={{header|J}}==
=={{header|J}}==
A brute force approach finds primes in the task range which are preceded by primes with appropriate offsets:
<syntaxhighlight lang=J> #sp2=: (#~ 1 p: _6+]) p1=:i.&.(p:inv) 1000035 NB. pairs
16386
(_6*i.-2)+/_5{.sp2
999371 999431 999721 999763 999953
999377 999437 999727 999769 999959
#sp3=: (#~ 1 p: _12+]) sp2 NB. triplets
2900
(_6*i.-3)+/_5{.sp3
997427 997541 998071 998617 998737
997433 997547 998077 998623 998743
997439 997553 998083 998629 998749
#sp4=: (#~ 1 p: _18+]) sp3 NB. quads
325
(_6*i.-5)+/_5{.sp4
977345 983765 986125 990365 997085
977351 983771 986131 990371 997091
977357 983777 986137 990377 997097
977363 983783 986143 990383 997103
977369 983789 986149 990389 997109
#sp5=: (#~ 1 p: _24+]) sp4 NB. quint
1
(_6*i.5)+/sp5
29
23
17
11
5
#unp=: p1-.,sp2-/0 6 NB. unsexy
48628
_10{.unp
999863 999883 999907 999917 999931 999961 999979 999983 1000003 1000033
</syntaxhighlight>

And here's a different approach:
<syntaxhighlight lang="j">NB. Primes Not Greater Than (the input)
<syntaxhighlight lang="j">NB. Primes Not Greater Than (the input)
NB. The 1 _1 p: ... logic here allows the input value to
NB. The 1 _1 p: ... logic here allows the input value to