+/+/@((=<.)@% >:@i.)"0 >:i.10
27

--- bill lam <[EMAIL PROTECTED]> wrote:

> eg. to count the number of pair (x,y) such that y is a factor of x for x,y 
> 0<x<:10
> use of function table is a good choice,
> fac=: (= <.)@%
>    fac/~ >:@:i. 10
> 1 0 0 0 0 0 0 0 0 0
> 1 1 0 0 0 0 0 0 0 0
> 1 0 1 0 0 0 0 0 0 0
> 1 1 0 1 0 0 0 0 0 0
> 1 0 0 0 1 0 0 0 0 0
> 1 1 1 0 0 1 0 0 0 0
> 1 0 0 0 0 0 1 0 0 0
> 1 1 0 1 0 0 0 1 0 0
> 1 0 1 0 0 0 0 0 1 0
> 1 1 0 0 1 0 0 0 0 1
>    +/ , fac/~ >:@:i. 10
> 27
> 
> furthermore if only proper factor is counted
>    +/ , ([EMAIL PROTECTED] i.10 ) *. fac/~ >:@:i. 10
> 17
> 
> BUT obviously processing the upper triangular (and diagonal) is reducdant.
> The time and space cost for large matrix may be significant.
> 
> Can anyone show how to do it without control structure?
> 
> TIA
> 
> bill
> 
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to