02-23-2019 10:53 AM
@altenbach wrote:
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?
It is really important to ask the right question and not make up partial solution steps that may or may not be needed. Originally you asked how to generate all the possible combinations while this is not even needed to solve the problem. 😄
So here is the solution that gives the four elements with the largest sum and the four elements with the smallest sum as well as their sums.
This assumes that there are no unusual values (such as NaN, etc.) in the array. If there are, you need to decide what to do and handle it accordingly.
(Of course generating all possible combinations is an interesting programming task too and we already showed you how to do that. Good exercise! Study it!)
02-23-2019 11:23 AM
@altenbach wrote:
(Of course generating all possible combinations is an interesting programming task too and we already showed you how to do that. Good exercise! Study it!)
Here's how that could look like, i.e. the solution to your original problem (except it is DBL instead of SGL, same basic code):
"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"
02-25-2019 09:01 AM
Thanks altenbach,
You are very helpful and quick in reply too
my requirement is still the original one, i.e to find all possible permutations ( sorry not combinations ) of 4 groups in total of 60 and i need indexes of these elements in array also (i.e 4 indexes for all permutations) for finding some other combinations like which all combination gives a value less than some given value or which all combinations gives sum between two given numbers etc.. not only maximum and minimum sum...
I have used your code ( 60c4 ) along with anther code to generate permutation for each of these combinations(4p4)..so finally i got 60p4.. there may be easier logics to do this...but i have managed with above solution...
02-25-2019 10:11 AM - edited 02-25-2019 10:30 AM
If order matters, I am sure you can still do it with one loop pyramid. Try it! You could generate all permutations for each right after the ToU8, or even change the logic completely. Even your smallest FOR loop needs to execute exactly once, and not gazillion times. It belongs on the toplevel diagram and not inside any loops, because the output never changes. Even the permutations can be calculated once and implemented as a lookup table.
It is not nice if you constantly change the problem specification on us. Can you give us the original and correct problem specification verbatim from the beginning instead? It is useless to solve the wrong problems because you don't tell us the whole story. That's now the third time you changed specs completely!!! 😮 Is this homework or school?
02-25-2019 05:06 PM
As I told in my last post, i need to find all possible permutations of 4 element groups in total of 60 elements and i need array indexes (indexes of 4 elements in 60 element array say for one permutation it is 5,17,25,58, for another it is 1,55,56,57 etc...total 11703240 permutations , 60p4) of these elements also for finding some combinations like which all permutations gives a value less than given value, which all combinations gives sum between two given numbers, which permutations gives maximum sum , which permutations gives minimum sum etc.. Hope this time my requirements are clear..
As i said in my last post, i have written a code clubbing your code with some other permutation code, and I am able to meet all my above requirements.. code is shown below, which gives me 4 index elements ( they are indexes of original 60 element array) for all 60p4 permutations .. rest of the code for finding max sum, min sum, any other combinations etc is not shown below..hope its clear now.. all my above requirements with this code..
Thank you once again for your help, suggestions and code..
02-25-2019 05:50 PM
Obviously, you did not understand what I meant. My suggestion will give the same result as yours, except more efficiently and with much less code clutter.
02-26-2019 12:51 AM
What I meant is that you calculate the permutations from scratch for each unique set while it is sufficient to do that exactly once. Here's what I had in mind. Now the permutations are created immediately in the main loop pyramid. Let me know if you have any questions.
(Seen you are using my old code here)