# Calculating total possible matching combinations remaining

#### charles1234

##### New member
Hello

I'm working on an application and I have a problem that I've been wrecking my brain over. The best way I can explain it is through a game.

There are 4 bags with numbered balls in each (the total number of balls in each bag is irrelevant). You have to guess the number that is going to be selected from each bag and you will win a prize if you match all 4 selections and also if you match 3 out of 4. You are also allowed to play combinations, meaning you can have multiple guesses for one or more of the bags. So for example, you can play a ticket that looks something like this:

Bag one: 1, 5
Bag two: 4, 6
Bag three: 1, 9
Bag four: 7, 9

In this case the ticket has 16 different combinations (2x2x2x2). I've used two selections in each for simplicity but there could be an arbitrary amount in each.

The question is: How can I calculate the remaining possible winning combinations in each prize category after a ball has been selected from the 1st bag, then 2nd bag etc.

So for example:

First ball chosen is number 1. The answer would be 16 combinations for 3 out of 4 and 8 combinations for 4 out of 4.
Second ball chosen is number 3. The answer would be 8 combinations for 3 out of 4 and 0 combinations for 4 out of 4.

The only way I've managed to do this is by breaking it up into all possible combinations and then calculating the possible matches on each one but is there an easier way without having to analyse every combination?

Thanks

Last edited: