LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding all possible Combination

I have a set of 60 data(single precision floating value of 1 d array of size 60). I would like to find all possible combinations of 4 elements at a time out of these 60( 60!/(4!× 56!) Is it Correct?). Can I use LabVIEW for finding this? Whether system will hang? Or do I need to take any special care?

0 Kudos
Message 1 of 17
(6,205 Views)

It seems easy enough to brute force. 🙂 If i'm correct the answer is 521800 combinations. (Hmm, I see a mistake now, let's see if you spot it)

Brute force.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 17
(6,181 Views)

Why reinvent the wheel. You can always use the built in VIs

 

built in VIs.png

 

btw the answer is 487635

Message 3 of 17
(6,170 Views)

Counting the number of combinations and generating an array containing all possible combinations are two different things. Do you really need the output all at once or would it be sufficient to generate and process one at a time without having a hardcopy of all of them at the end?

In any case, definitely don't do this in SGL. As Yamaeda demonstrated, U8 is plenty to uniquely define the index of each of the 60 elements.  Personally, I would probably do it a bit differently, but I don't have time right now to look into it in more detail.

 

Can you explain the purpose of this exercise? Are all 60 elements unique or could there be duplicates?

0 Kudos
Message 4 of 17
(6,160 Views)

(Finally got off the bus and had a minute to show what I had in mind...)

 

Here is the "dumb" code that seem to also give 487635 possibilities in agreement with jamiva. No guarantees. Maybe it can be simplified?

 

Pick4of60.png

 

 

Now "smarter" code would use a single loop and allow the number of picks to also be a variable input. Scalability is the key here!

Try it 😄

0 Kudos
Message 5 of 17
(6,130 Views)

Thanks Jaiva, for your reply..My need is not to find how many combinations, but all combinations..no of possible combinations are nCr, ie easy to find, but I want each combinations, so for my final output should be array of 487635 x 4 elements?

0 Kudos
Message 6 of 17
(6,102 Views)

thank you very much for your reply, my need is to find sum of these 4 elements for all possible combinations and find which two combination gives me maximum and minimum for this sums. All 60 elements are different random values. My final output can be only two combinations out of these 487635 possible combinations which gives me maximum sum and minimum sum..That's all..I don't want all combinations as my output..

0 Kudos
Message 7 of 17
(6,099 Views)

Thanks for your efforts..I will further develop your code to meet my requirements, my need is to find sum of these 4 elements for all possible combinations and find which two combination gives me maximum and minimum for these sums. All 60 elements are different random values( i have these values as an array of 60 elements). My final output needs to  be only two combinations out of these 487635 possible combinations which gives me maximum sum and minimum sum..Your code gives me array indexes and I will find sum and difference using this indexes, then find maximum sum and minimum sum and corresponding combinations.

0 Kudos
Message 8 of 17
(6,092 Views)

@satcr wrote:

thank you very much for your reply, my need is to find sum of these 4 elements for all possible combinations and find which two combination gives me maximum and minimum for this sums. All 60 elements are different random values. My final output can be only two combinations out of these 487635 possible combinations which gives me maximum sum and minimum sum..That's all..I don't want all combinations as my output..


We'll, that's a different problem, so take your array of random values into the innermost loop and  use my four values to index out the four corresponding elements from the random array, add them, and feed them into ptbypt min&max. That's all. See how far you get. ( I am currently not at a computer).

0 Kudos
Message 9 of 17
(6,090 Views)

To get the max and min sum, all you need to do is sort the array and sum the last four and first four element of the sorted array, respectively. Right?

0 Kudos
Message 10 of 17
(6,081 Views)