0
$\begingroup$

I have a Lottery app and I'm implementing a feature to optimize the number of bets that are necessary to cover a subset of numbers since they can repeat on several bets.

What I have:

Supposing a lottery where you can select 6 numbers from 1 to 60. Then, 6 numbers are draw and you win if you correctly guess 4 or 5 or all 6 numbers.

When creating a bet, you can "emulate" a bet with 9 numbers by finding all possible combinations with them (combination without repetition). In this example:

$$ C_{6}^{9} = \frac{n!}{k!(n-k)!} = \frac{9!}{6!(9-6)!} = 84 $$

In other words, I need to create 84 bets to cover all combinations of 6 numbers among those 9.

I've already created the code to calculate and find all combinations.

Feature I want to implement

Supposing I not interested in the main prize (6) but on the lowest prize: 4. In this case, I don't need to create all 84 bets. With fewer bets, I can cover all combinations of 4 numbers from those 9 I started.

In the end, I want two things:

  1. Find the minimum amount of bets (with 6 numbers) I need to create in order to cover all possible combinations of 4 numbers among those 9.

  2. Generate those bets.

Some example

I found some samples on the internet but I didn't manage to implement the algorithm or find the math behind it. In the sample I found:

The 9 numbers I want to bet: $$ S = \\{ 07, 12, 24, 32, 37, 41, 42, 54, 55 \\} $$

Instead of creating 84 bets, I can create 12 bet and I would still win the 4-numbers prize if 4 of those 9 numbers are correct.

Result

$T_1 = \\{ 07, 12, 24, 32, 37, 41 \\}$ $T_2 = \\{ 07, 12, 24, 42, 54, 55 \\}$ $T_3 = \\{ 07, 12, 32, 37, 42, 54 \\} $
$T_4 = \\{ 07, 12, 32, 41, 54, 55 \\}$ $T_5 = \\{ 07, 12, 37, 41, 42, 55 \\}$ $T_6 = \\{ 07, 24, 32, 37, 54, 55 \\}$
$T_7 = \\{ 07, 24, 32, 41, 42, 55 \\}$ $T_8 = \\{ 07, 24, 37, 41, 42, 54 \\}$ $T_9 = \\{ 12, 24, 32, 37, 42, 55 \\}$
$T_10 = \\{ 12, 24, 32, 41, 42, 54 \\}$ $T_11 = \\{ 12, 24, 37, 41, 54, 55 \\}$ $T_12 = \\{ 32, 37, 41, 42, 54, 55 \\}$

I would appreciate if someone give some direction because I'm not being able to move forward

$\endgroup$
2

1 Answer 1

1
$\begingroup$

This might be better asked on MathStackExchange, although the underlying question leads to interesting problems. You might look at the following excerpt from Jordan Ellenberg's book How Not to Be Wrong: The Power of Mathematical Thinking that describes a strategy for buying lottery tickets to minimize the variance. Not exactly the question that you're asking, but of a similar flavor, since one wants to avoid duplication.

$\endgroup$
1
  • $\begingroup$ Thank you @JoeSilverman.. I'll definitely take a look $\endgroup$
    – guipivoto
    Commented Dec 27, 2023 at 22:53

Not the answer you're looking for? Browse other questions tagged .