Sexy primes: Difference between revisions

→‎{{header|J}}: fix unsexy bug
m (→‎{{header|J}}: spacing)
(→‎{{header|J}}: fix unsexy bug)
Line 966:
 
sp =: dyad define
's os' =. x NB. prime distance, grouporgy size
p =. pngt y
o =. orgy p
Line 974:
l =. (({.~ -) 5 <. #)&.> g NB. Last (max) 5 groups
 
NB. I'm sure there's something clever with p-.s or similar,
( (#&.> g) ,. l ) ,~ (# ; _10&{.) }: p -. s NB. Unsexy numbers; }: is to exclude 1000033 per spec
NB. but (a) I don't want to think through it, and (b)
)</lang>
NB. it causes the kind of edge-case issues the spec warns
NB. about with 1000033
us =. _6 6 (] #~ [: +:/ 1 p: +/) p NB. Unsexy numbers
( (#&.> g) ,. l ) ,~ (# ; _10&{.) us
)
 
r =: 1000035 sp~ SEX,ORGY_SIZE
smoutput (;:'Group Count Examples') , (;:'Unsexy Pair Triplets Quadruplets Quintuplets') ,. r</lang>
 
{{out}}
Line 983 ⟶ 991:
|Group |Count|Examples |
+-----------+-----+----------------------------------------------------------------------+
|Unsexy |7849948627|999853 999863 999883 999907 999917 999931 999953 999959 999961 999979 999983 1000003|
+-----------+-----+----------------------------------------------------------------------+
|Pair |16386|999371 999377 |
Anonymous user