LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Easiest way to sum all possible (different) combinations in an array?

Solved!
Go to solution

Hey guys, 

 

Say I have an array of sorted values (of attenuation), I want to generate an array of all possible sums of those values, sort it, then refer to it as a list of all possible attenuation values (lets say theyre bits on a discrete digital attenuator).  I will try to show you an example of what I mean with letters:

 

Array of attens: [a, b, c, d]

 

I want an array like this: [a+b,  a+c,  a+d,  a+b+c,  a+b+d,  a+c+d,  b+c,  b+d,  b+c+d]... I hope I'm not missing any combos here...

 

I'm attaching my attempt at this idea but there's something missing I think, I am doing something wrong...

 

Thanks for any ideas or help.

 

 

0 Kudos
Message 1 of 7
(7,833 Views)

I wish I had LabVIEW with me.  This sounds like a fun problem.  I'm thinking this might be a good case for recursion.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(7,809 Views)

I actually switched up the vi I'm using to concatenate strings instead of summing integers so I can tell which elements were added.

 

It's fun to think about for a little while, but Ive been working on this for most of the day and not getting very far... sad.

0 Kudos
Message 3 of 7
(7,800 Views)
Message 4 of 7
(7,778 Views)
Solution
Accepted by topic author plyons.gks

The challenge is getting all possible combos.

 

Have you concidered looking at this as a variation on binary counting?

 

The total number of combinations is 2^(NumberOfSettings) if you include "None".

 

So generate a ramp from zero to the total number possible.

 

Convert each number to a boolean array and then use the boolean to determine if its corresponding value gets add into the total.

 

After processing all of the values from the ramp the final array should be in ascending order.

 

I hope that outline helps,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(7,775 Views)

@Ben wrote:

The challenge is getting all possible combos.

 

Have you concidered looking at this as a variation on binary counting?

 

The total number of combinations is 2^(NumberOfSettings) if you include "None".

 

So generate a ramp from zero to the total number possible.

 

Convert each number to a boolean array and then use the boolean to determine if its corresponding value gets add into the total.

 

After processing all of the values from the ramp the final array should be in ascending order.

 

I hope that outline helps,

 

Ben


Ben, that is actually quite brilliantly simple.  I like it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 7
(7,768 Views)

So I ran across this again and by remembering Ben's suggestion, threw thi VI together in no time at all... thought I'd upload to save someone else time... and try to give a lil back hopefully haha

 

thanks again man

 

-pat

Message 7 of 7
(7,663 Views)