HOW CAN I FIND THE SUBSET OF N-SET?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Given S={1,2,3,4,5,6...................n}
Find the subset of S whose element has j without rand or function.
I want to find this answer with using only for,while,etc....
example) S={1,2,3,4}, j=2
ANSWER= {1 2} {1 3} {1 4} {2 3} {2 4} {3 4}
3 Commenti
Risposte (2)
Walter Roberson
il 30 Ott 2020
See the "odometer" code that I posted at https://www.mathworks.com/matlabcentral/answers/623358-get-a-combination-of-unique-paths-for-given-pair-of-numbers#comment_1082638
You would use as many positions as you wanted to select at the same time, and you would use the rule that the elements must be sorted -- so when you increment something to the left, have a pass back towards the right in which you set the entries to increasing integers, and re-increment if that does not fit. For example your limit is 6 and you are at 1 3 5 6 then "odometer" would roll to 1 3 5 7 carry left -> 1 3 6 1, fix up to right -> 1 3 6 (6+1->overflow) so 1 3 6 1 carry left again -> 1 3 (6+1->overflow) 1 so carry left on the overflow -> 1 4 1 1 now fix up to right -> 1 4 (4+1) (4+1+1) = 1 4 5 6 which is valid. (There would be better ways to implement this in practice.)
1 Commento
Walter Roberson
il 30 Ott 2020
If this Answer did not work for you, then it would be better if you were to comment as to what difficulties you ran into when using it. I cannot improve the answer if I do not know what went wrong for you.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!