‎02-22-2019 09:50 AM
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?
‎02-22-2019 10:25 AM - edited ‎02-22-2019 10:27 AM
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)
/Y
‎02-22-2019 10:38 AM
Why reinvent the wheel. You can always use the built in VIs
btw the answer is 487635
‎02-22-2019 10:50 AM - edited ‎02-22-2019 10:50 AM
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?
‎02-22-2019 01:01 PM
(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?
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 😄
‎02-22-2019 10:07 PM
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?
‎02-22-2019 10:14 PM
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..
‎02-22-2019 10:28 PM
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.
‎02-22-2019 10:32 PM
@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).
‎02-22-2019 11:44 PM
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?