Remarkably, I was just thinking about such a divisor verb (since I needed it
to represent an array as a matrix) and came to
(3 :('b, y%|. b=.a#~ 0=y|~ a=.i.&.<: >.%:y'))51
1 3 17 51
(3 :('b, y%|. b=.a#~ 0=y|~ a=.i.&.<: >.%:y'))360
1 2 3 4 5 6 8 9 10 12 15 18 20 24 30 36 40 45 60 72 90 120 180 360
Or tacitly
(](([, (% |.))]#~ 0=|~) [:i.&.<: >.@%:)
R.E. Boss
(Add your info to http://www.jsoftware.com/jwiki/Community/Demographics )
> -----Original Message-----
> From: [email protected] [mailto:programming-
> [email protected]] On Behalf Of Roger Hui
> Sent: dinsdag 10 juni 2014 19:19
> To: Programming forum
> Subject: Re: [Jprogramming] Shorten a verb
>
> From http://www.jsoftware.com/jwiki/Essays/Divisors
>
> div=: /:~ @: , @: > @: (*/&.>/) @: ((^ i.@>:)&.>/) @: (__&q:)
> div 360
> 1 2 3 4 5 6 8 9 10 12 15 18 20 24 30 36 40 45 60 72 90 120 180 360
>
>
>
>
>
> On Tue, Jun 10, 2014 at 10:10 AM, Jon Hough <[email protected]>
> wrote:
>
> > My attempt at making a verb that finds the total of all proper divisors
of
> > an integer seems to work.
> > e.g. if n = 12, the sum of proper divisors is 1 +2 +3+4+6 = 16 (note 12
is
> > not included)
> > This verb is actually equal to the "sigma function" minus n.Wikipedia
> > explanation: http://en.wikipedia.org/wiki/Divisor_function
> > (I essentially used the equation for sigma_x(n) where x = 1)
> > my verb:
> >
> > sum =.(((*/@:-&1@:{.)%~(*/@:-&1@:({.^(1&+@:,@:}.))))@:(2&p:))-]
> > This seems ok, but is not aesthetically pleasing, and seems to be very
> > bracketty, and given that the mathematical equation is pretty concise I
am
> > surprised the J verb is so long. If anyone knows a nicer way of doing
this
> > I would be grateful to see it.
> > Regards.
> > ----------------------------------------------------------------------
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm