Here are some expressions of another approach:
   1 2 3 4 5 (,&(+/) +/ .* ,~&#) 1 2
   1 2 3 4 5 (,&(+/) +/@:* ,~&#) 1 2
   1 2 3 4 5 ((+/@] * [EMAIL PROTECTED]) + +/@[ * [EMAIL PROTECTED]) 1 2
   1 2 3 4 5 ((] * [EMAIL PROTECTED]) +/@, [ * [EMAIL PROTECTED]) 1 2
   1 2 3 4 5 ((* #)~ +/@, (* #)) 1 2

I am not sure how comfortable you are, reading J, but note that
you can break these down and examine the results of
subexpressions:
   1 2 3 4 5 (* #) 1 2
2 4 6 8 10
   1 2 3 4 5 (* #)~ 1 2
5 10
   2 4 6 8 10 +/@, 5 10
45

The basic concept, here, is that you multiply each of the numbers
by the number of numbers from the other argument, and then
you add them all up.  [If both of your argument lists were longer,
I believe that this approach would be more efficient than using pure
repeated addition.]

Also if you have not encountered J's hooks and forks before, you
might want to refer to http://www.jsoftware.com/help/dictionary/dictf.htm

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

Reply via email to