I know there are quite some questions out there on generating combinations of elements, but I think this one has a certain twist to be worth a new question:
For a pet proejct of mine I've to pre-compute a lot of state to improve the runtime behavior of the application later. One of the steps I struggle with is this:
Given N tuples of two integers (lets call them points from here on, although they aren't in my use case. They roughly are X/Y related, though) I need to compute all valid combinations for a given rule.
The rule might be something like
I hope and expect that this fact leads to an improvement in the selection process, but my math skills are just being resurrected as I type and I'm unable to come up with an elegant algorithm.
Thanks.
Update in response to Vlad's answer:
Maybe my idea to generalize the question was a bad one. My rules above were invented on the fly and just placeholders. One realistic rule would look like this:
By that rule and by choosing (2,1) I'd exclude
So the rules are fixed, not general. They are unfortunately more complex than the X/Y samples I initially gave.
The formula for combinations is nCr = n! / r! * (n - r)!, where n represents the number of items, and r represents the number of items being chosen at a time.
There are 10,000 possible combinations that the digits 0-9 can be arranged into to form a four-digit code.
Note that your choice of 5 objects can take any order whatsoever, because your choice each time can be any of the remaining objects. So we say that there are 5 factorial = 5! = 5x4x3x2x1 = 120 ways to arrange five objects.
Thus, for 5 objects there are 5! = 120 arrangements.) For combinations, k objects are selected from a set of n objects to produce subsets without ordering.
How about "the x coordinate of every point included is the exact sum of some subset of the y coordinates of the other included points". If you can come up with a fast algorithm for that simply-stated constraint problem then you will become very famous indeed.
My point being that the problem as stated is so vague as to admit NP-complete or NP-hard problems. Constraint optimization problems are incredibly hard; if you cannot put extremely tight bounds on the problem then it very rapidly becomes not analyzable by machines in polynomial time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With