The simplest way is to give the definition zero rank. (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))"0]10 12 28 0 0 1
On Tue, Aug 9, 2011 at 1:54 PM, Uriel Zylbermann <[email protected] > wrote: > Hi, I'm new to J so my programs might be a bit more complicated than > needed, > I would be happy if you could tolerate that(and perhaps even give me fixes > when needed). > > anyway, I have a monad function that checks if a number is a perfect > number: > > (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1)))) > > this monad works for single numbers: > > (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))10 > 0 > (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))12 > 0 > (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))28 > 1 > > but for lists it gives me a length error for some reason: > > (<([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))10,12,28 > |length error > | (<([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))10,12,28 > it was my understanding that a monad, when applied to a list, will work for > each element separately and then return the list of result, like this: > > >:i.10 > 1 2 3 4 5 6 7 8 9 10 > > I would be very grateful for any help understanding my error, thanks in > advance, Uriel. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
