Sexy primes: Difference between revisions
Content added Content deleted
m (→{{header|J}}: capped fork -> Atop) |
(→{{header|J}}: max SEX and ORGY_SIZE free parameters rather than global constants (this was inconsistent before)) |
||
Line 951: | Line 951: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<lang j> |
<lang j>NB. Primes Not Greater Than (the input) |
||
ORGY_SIZE =: 5 NB. Max group size |
|||
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 |
||
NB. be included in the list in the case it itself is prime |
NB. be included in the list in the case it itself is prime |
||
Line 960: | Line 957: | ||
NB. Add 6 and see which sums appear in input list |
NB. Add 6 and see which sums appear in input list |
||
sexy =: #~ |
sexy =: ] #~ ] e.~ + |
||
NB. Iterate "sexy" logic up to orgy size |
NB. Iterate "sexy" logic up to orgy size |
||
orgy =: sexy&.>^:( |
orgy =: sexy&.>^:( ({.@:[) ` (<@:{:@:[) ` (<@:]) ) |
||
sp =: dyad define |
sp =: dyad define |
||
'pd os' =. x NB. prime distance, orgy size |
'pd os' =. x NB. x is prime distance (6), orgy size (5) |
||
p =. pngt y |
p =. pngt y |
||
o =. orgy p |
o =. x orgy p |
||
g =. o +/&.> <\ +/\ _1 |.!.0 os # pd NB. Groups |
g =. o +/&.> <\ +/\ _1 |.!.0 os # pd NB. Groups |
||
Line 980: | Line 977: | ||
us =. p (] #~ 1 +:/@:p: +/)~ (+,-) pd NB. Unsexy numbers |
us =. p (] #~ 1 +:/@:p: +/)~ (+,-) pd NB. Unsexy numbers |
||
( (#&.> g) ,. l ) ,~ (# ; _10&{.) us |
( (#&.> g) ,. l ) ,~ (# ; _10&{.) us |
||
)</lang> |
|||
) |
|||
r =: 1000035 sp~ SEX,ORGY_SIZE |
|||
smoutput (;:'Group Count Examples') , (;:'Unsexy Pair Triplets Quadruplets Quintuplets') ,. r</lang> |
|||
{{out}} |
{{out}} |
||
<lang j> r =: |
<lang j> r =: 6 5 sp 1000035 NB. 6=sex=prime distance, 5=max orgy size |
||
(;:'Group Count Examples') , (;:'Unsexy Pair Triplets Quadruplets Quintuplets') ,. r |
smoutput (;:'Group Count Examples') , (;:'Unsexy Pair Triplets Quadruplets Quintuplets') ,. r |
||
+-----------+-----+----------------------------------------------------------------------+ |
+-----------+-----+----------------------------------------------------------------------+ |
||
|Group |Count|Examples | |
|Group |Count|Examples | |