[Jprogramming] learning: Having trouble writing loopless scripts

Rob Hodgkinson rhodgkin at bigpond.net.au
Thu Aug 7 13:02:39 HKT 2008


You could have generalised your original 'c' using 'rank' as follows:

    c=: 4 : '(!(x+y)) % (x+y)'         NB. As you had below ...
    a=:1 2 3 4 5
    b=:1 2 3

    a c"0 _ b                     NB. Apply c to each 'scalar item' of  
a, against 'whole' of b
   1   2    6
   2   6   24
   6  24  120
  24 120  720
120 720 5040


On 07/08/2008, at 5:07 AM, Ian Gorse wrote:

> ...
> If I was to extend it slightly, I have this
>
> c=: 4 : '(!(x+y)) % (x+y)'
> a=: 1 2 3 4 5
>
> and the result I want are
>   a c 1
> 1 2 6 24 120
>   a c 2
> 2 6 24 120 720
>   a c 3
> 6 24 120 720 5040
>
> ...
>
> c2=: 4 : '(!(a+/b)) % (a+/b)'
>
> NB. Third Approach
> a c2 b
>  1   2    6
>  2   6   24
>  6  24  120
> 24 120  720
> 120 720 5040
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list