On Thu, Sep 15, 2011 at 4:18 PM, David Vaughan
<[email protected]> wrote:
> Hi,
>
> I have a dyadic verb I wish to apply to x and y where x>y and 0<x<24, 0<=y<x.
>
> I want to be able to apply the verb to every single possible pairing of x and 
> y that is legal (i.e. where x>y).
>
> If it were C I would just do:
>
> for(x=1;x<24;x++)
> for(y=0;y<x;y++)
> {
>        // do verb on x and y
> }
>
> So I need an equivalent to that basically, in J.

What kind of results do you want?

Anyways,

  X f^:(13 :'(x>y)*.(0<x)*.(x<24)*.(0<y)*.(y<x)')"0/ Y

Or, since
   13 :'(x>y)*.(0<x)*.(x<24)*.(0<y)*.(y<x)
> *. (0 < [) *. (24 > [) *. > *. 0 < ]

You could use
  X f^:(> *. (0 < [) *. (24 > [) *. > *. 0 < ])"0/ Y

And since one of those comparisons was redundant:
  X f^:(> *. (0 < [) *. (24 > [) *. 0 < ])"0/ Y

Actually, another of those comparisons was redundant (if y<x and 0<y
you do not need to check that 0<x):
  X f^:(> *. (24 > [) *. 0 < ])"0/ Y

Finally, note that I used X and Y for the data references, rather than
x and y, because it's bad practice to use x and y in J for persistent
data.

FYI,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to