Geoff - if you really mean "all possible sums", you should be expecting a
lot more results.
For your example "i. 5 3", there should be 3^5 possible sums (including
duplicates).
If this is the case,
   {<"1 i. 2 3 NB. All possible combos of 1 from each row
+---+---+---+
|0 3|0 4|0 5|
+---+---+---+
|1 3|1 4|1 5|
+---+---+---+
|2 3|2 4|2 5|
+---+---+---+
   +/&>{<"1 i. 2 3 NB. Add up each
3 4 5
4 5 6
5 6 7
   ^~/$i. 5 3 NB. Size of expected result
243
   $,+/&>{<"1 i. 5 3 NB. Add up each
243
   ~.,+/&>{<"1 i. 5 3 NB. Only unique sums
30 31 32 33 34 35 36 37 38 39 40

NB. For more unique solutions, use matrix that's not necessarily an
Arithmetic Progression Vector:
   rm=. ?5 3$1000 NB. Try with random matrix
   $~.,+/&>{<"1 rm NB. Add up each
240

But this does not look like the result in your example so perhaps I've
gotten it wrong.

Regards,

Devon


On 2/5/08, Geoff Canyon <[EMAIL PROTECTED]> wrote:
>
> I want to write a function that will take a rank 2 array and then find
> all the possible sums, taking one number from each row. After much
> puzzlement I finally figured out that +// was the likely the direction
> I wanted, and based half on my own limited understanding of how to
> make things tacit and half on 13 : here's what I have so far:
>
>     f=:[: ~. ([: ~. [: , +/)/
>     c=: i.5 3
>     f c
> 15 16 17 18 19 20 21 22 23 24 25 26 27
>
> Does that seem like the right way to go? (I can't even begin to figure
> out how to replace those caps with @ and @:
>
> regards,
>
> Geoff
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to