Very cool Crypto Geek!
So now I want make a generic verb using Crypto Geek's technique:
NB. Generic verb - sum numbers in range y that is of divisible by x
NB. x = divisor
NB. y = range (low, high)
sd=. 4 : '+/(-x){.\({.y)+i.1+-/|.y'
NB. Also, using my original method, after cleaning it up a bit:
sd1 =. 4 : '+/a#~0=x|a=.({.y)+i.1+-/|.y'
NB. Test them out:
5 sd 100 999
98550
5 sd1 100 999
98550
NB. Looking good. Try some different divisors:
r =. 100 999
(5 sd r) -: 5 sd1 r
1
(50 sd r) -: 50 sd1 r
1
(100 sd r) -: 100 sd1 r
1
(200 sd r) -: 200 sd1 r
0
NB. Uh oh! Somethings wrong...
200 sd r
2500
200 sd1 r
2000
NB. Find the list of all numbers in the range evenly divided by 200, using
my old method:
a#~0=200|a=.({.r)+i.1+-/|.r
200 400 600 800
NB. Now using Crypto Geek's method:
_200{.\100 + i.900
100 300 500 700 900
Aha! I see the problem. I'm not sure how to fix Crypto Geek's method so it
will generalize over all divisors, though.
Skip
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm