Early in this long thread, I wanted to remove B from f below. I found the answer.
(3 :'~.b, y%|. b=.a#~ 0=y|~ a=.>:i. <.%:y')36 NB. R.E. Boss 1 2 3 4 6 9 12 18 36 Look at the difference if I change B=: to B=. f=: 13 :'/:~~.*/"1(0=B)+(B=:#:i.2^$1,q:y)(*"1)1,q:y' f 3 : '/:~~.*/"1(0=B)+(B=:#:i.2^$1,q:y)(*"1)1,q:y' g=: 13 :'/:~~.*/"1(0=B)+(B=.#:i.2^$1,q:y)(*"1)1,q:y' g [: /:~ [: ~. [: */"1 ([: #: [: i. 2 ^ [: $ 1 , q:) ((0 = [) + *"1) 1 , q: sdiv8 =: >:@#.~/.~&.q: (+/g 360)-:sdiv8 360 1 It still works and all I have to do is try to go backward from the tacit to the explicit form! Linda -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Linda Alvord Sent: Tuesday, June 10, 2014 3:50 PM To: [email protected] Subject: Re: [Jprogramming] Shorten a verb Here's a slow scenic route to the solution. I wish I could eliminate B. f=: 13 :'/:~~.*/"1(0=B)+(B=:#:i.2^$1,q:y)(*"1)1,q:y' (div 360)-:f 360 1 Linda -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Roger Hui Sent: Tuesday, June 10, 2014 1:19 PM 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
