Hi all!

    a=: 2 5 7
    f=: 1 :'/:~ (#: }. i.2^#y) u@# y'
   +/f a
2 5 7 7 9 12 14
   */f a
2 5 7 10 14 35 70
   <f a
┌─┬───┬─────┬───┬─┬───┬─┐
│2│2 5│2 5 7│2 7│5│5 7│7│
└─┴───┴─────┴───┴─┴───┴─┘

With the no element combination deliberately dropped.

Cheers,
Erling



On 2017-10-03 00:45, Erling Hellenäs wrote:
Hi all !

   a=: 2 5 7
   f=: 1 : '/:~(#: }. i. 2 ^ # y) ([: u/ #) /"1 y'
   + f a
2 5 7 7 9 12 14
   * f a
2 5 7 10 14 35 70

Cheers,
Erling

On 2017-10-02 19:45, Erling Hellenäs wrote:
Hi all!

You don't want the combination of zero elements?

   a=: 2 5 7
   /:~(#: i. 2 ^ # a) ([:+/#) /"1 1 a
0 2 5 7 7 9 12 14
   /:~(#: i. 2 ^ # a) ([:*/#) /"1 1 a
1 2 5 7 10 14 35 70

Guess I could drop it.

Cheers,

Erling

On 2017-10-02 18:49, Skip Cave wrote:
Given a set of integers, what is the most concise and or efficient way to list the numbers along with the sum of all combinations of the numbers? the
products of all combinations?

for example:

a =. 2 5 7
+ f a    NB. 2, 5, 7, (2+5), (2+7), (5+7), (2+5+7)
2 5 7 7 9 12 14

* f a    NB. 2, 5, 7, (2*5), (2*7), (5*7), (2*5*7)
2 5 7 10 14 35 70

The function 'f' should work for any verb and any size right argument noun
vector.

Skip

Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


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


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


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

Reply via email to