To avoid each,
(#~ ([EMAIL PROTECTED])@((>:i.6) <@/:~@":@* ])"0) i.200000
0 142857
--- Roger Hui <[EMAIL PROTECTED]> wrote:
> Functions are usually composed with @ or @: ;
> juxtaposition works only if the desired composition
> is a hook or a fork. Thus instead of
> =/ /:~ each ": each <"0 (>:i.6)*]
> you need to say
> =/@:(/:~ each)@:(": each)@:(<"0)@:((>:i.6)*])
>
> The number of "each"es can be reduced as follows:
> =/@:(/:~@:": each)@:((>:i.6)*])
>
> =/ is not the right thing to do to compute
> "whether they are all the same". Instead, do
> 1&=@:#@:~.@:(/:~@:": each)@:((>:i.6)*])
>
> On the face of it, f y would be 1 only if y is 0
> and is 0 otherwise. Perhaps you mean something
> other than "whether they are all the same".
>
> f=: 1&=@:#@:~.@:(/:~@:": each)@:((>:i.6)*])
> f"0 i.20
> 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> I. f"0 i.2000
> 0
>
>
>
> ----- Original Message -----
> From: Geoff Canyon <[EMAIL PROTECTED]>
> Date: Monday, March 19, 2007 11:31 pm
> Subject: [Jprogramming] monad vs. dyad
>
> > I'm trying to write a monadic function that will take a number,
> > create a list of that number times 1..6, with each number's
> > characters sorted, and return whether they are all the same. So f
> > 17
> > would look at the list 17 34 15 68 58 012 and return 0. Here's my
> > closest attempt so far:
> >
> > =/ /:~ each ": each <"0 (>:i.6)*]
> >
> > <"0 (>:i.6)*26 returns
> >
> > +--+--+--+---+---+---+
> > |26|52|78|104|130|156|
> > +--+--+--+---+---+---+
> >
> > But
> >
> > f=:<"0 (>:i.6)*]
> > f 26
> > 0 1 1 1 1 1
> >
> > That looks to me like < is being treated dyadically, and returning
> >
> > false, true, true, etc. What do I need to do to force it to box
> > instead?
> > =/ /:~ each ": each NB. seems to work, but is there a better way
> > than
> > two eaches?
> >
> > Finally, putting it all together:
> >
> > f=: =/ /:~ each ": each <"0 (>:i.6)*]
> > f 4
> > |domain error: f
> > | f 4
> >
> > Any suggestions?
> >
> > thanks,
> >
> > geoff
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm