Sexy primes: Difference between revisions

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