I have an array of Card
instances.
Card[] allCards;
I am supposed to get all the possible combinations of these cards, under the following conditions:
- All of the combinations must have a minimum of 3 cards.
- A combination has no card limit (so if there are a total of 15 cards, you know there can be a combination of 15 cards, others of 13, 10, etc).
For college purposes, I am not supposed to use any fancy library capable of doing this job easier.
I've done it with pairs, sure, but considering that there is no limit, the algorithm I would usually do would not work.
It is pretty much what they ask here for python: Find all possible combinations
Any ideas? I don't want code or anything - I'm just lost with the algorithm/idea.
My Problem (more detailed)
I can make pairs by making two loops (one within the other). I can make triplets by having three loops (one within another within another).
But I don't know how to do this specific problem because:
- What if the array has 15 cards? I can't write 15 loops...
- And then of course I need to go down to 14, 13, 12 loops... (because all the combinations are not of 15 elements each, there can be combinations of 14, 13, 12 elements when working with this 15-elements-array)
I can find some combinations, but not dynamically.