Here is the problem: given a set of bets, how can I calculate the maximum possible wins of all combinations without looping through them?

I know how to get the number of combinations ($\frac{n!}{r!(n - r)!}$) and I know how to get the powerset, so all the single combinations.

In order to calculate the total possible wins, I am currently looping through all the combinations, multiplying the odds together and then adding them all to the total.

As you know, though, combinations add up pretty quickly as I add more bets, so I will soon looping through thousands of combinations and my program slows down.

Now, before I start to optimise those loops and improve the UX, if there was a mathematical formula to calculate the max possible wins, the looping problems will instantly vanish.

I have searched extensively, but I couldn't find anything. I might be lacking the proper mathematical terminology to actually find the answer I am looking for. But this looks like something mathematicians would have already solved, probably in different fields and with a specific name that I can't find.

For this example, I will assume all stakes are 1, so it's easier to handle.

3 bets with odds: 1,40 | 1,45 | 1,55

7 combinations (technically there is another combination where no bets are chosen, but we can skip that, because it wouldn't add anything to the sum):


If you round each calculation to two decimals, you get 14,00 (otherwise, 13,99).

Is there a formula to get to that result without looping through the powerset and calculating everything sequentially?


No, and if you're talking about sports-betting then your code should also take into account that some combinations aren't permissible and so can't contribute to the final total (if you want an accurate total -- see below). For example, your three selections may have two from the same match, so three singles, two doubles and no trebles are permissible, which is 5 from the seven possible.

Typically, when writing code for sports-betting sites (I spent 11 years working for a major supplier of sports-betting software) the rule we applied was to underestimate the maximum winnings. Customers are never upset to find out they've won more than they were told, but if you say the maximum is higher than they get when all the selections win, you can expect complaints and possibly even legal action. If you're happy to provide a lower bound then you can take the selection in order of ascending odds (e.g. 1.17, 1.41, 1.88, 2.05, 3.00) and then take the first two as the price for all doubles, the first three for all trebles, etc.

You still have the issue of what to do when selections aren't allowed to combine as this reduces the number of permissible bets. We used look-up tables: this number of selections (3) has this number of bets(7) if all combos are permitted, this number (5) if one selection does not combine, and this number(3) if two don't.

Lastly: if you have any kind of starting price you can't display the max winnings at all unless you're willing to estimate for SP.

  • $\begingroup$ Many thanks for taking the time to answer my question. For this specific calculation we already know that all bets are possible (otherwise this bit of the program is not reached at all).Also, at the moment, I am required to provide a precise value, not an estimation. As far as I understood, specific legislations require us to provide a precise value, or maybe it's just a business decision. So, I guess I am stuck with looping for now. Thanks again. $\endgroup$ – Emanuele Feliziani Dec 10 '18 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.