List all combinations of 6/36 with unique 4 numbers
"Martin-888" wrote:
I would like Excel to give me all the possible combinations
of a 6/36 lottery, but only to win the 4 out of 6 numbers.
I would like to help.
But first, let's agree to ignore those whose only comment is to pontificate
about how foolish playing the lottery is. Yes, yes, yes; just like all
gambling. But it presents some very interesting, if not fun, mathematical
problems. After all, it was the analysis of games of chance that gave rise
to probability theory in the first place.
So I am not judging your motivations. "Frankly, my dear, I don't give a
damn!" :-)
But I am curious, because this question has come up before.
So please explain the context of this question.
For example, is it a class assignment?
Or is it part of a lottery strategy? If so, can you explain the strategy,
or can you point to a (free) website that does?
"Martin-888" wrote:
There should be around 320 combinations.
For example these would be valid combinations:
1 2 3 4 5 6
1 2 3 7 8 9
1 2 4 10 11 12
These wouldn't be valid:
1 2 3 4 5 6
1 2 3 4 5 7
2 3 4 6 10 11
because "1 2 3 4" and "2 3 4 6" are appearing twice.
Based on this example, I think a better description of your objective is:
all combinations of 6 out of 36 numbers with a unique set of 4 numbers.
It has nothing to do with "winning" 4 out of 6. To me, that means:
matching 4 out of 6 compared to some drawing of 6 numbers. That's a very
different problem; an easier problem to solve, IMHO.
Anyway, what makes you think there are only "around 320" such combinations?
I believe the correct count is 2240.
At the risk of reinventing the wheel (I cannot find my comments in the
previous discussion), I implemented an algorithm that counts and generates
all of the qualified combinations by exhaustively generating all
COMBIN(36,6) combinations (1,947,792) and keeping track of the ones with
unique sets of 4 numbers. It only takes about 1 second on my computer.
(YMMV.)
I will share that implementation with you after you answer my questions
above.
In the meantime, I am still improving the implmentation so it is easier for
public consumption. I would also like to see if there is a better
algorithm. And I am still strugging to derive a computational method for
counting the number of combinations.
In any case, be advised that this cannot be done with Excel alone. Instead,
it requires a VBA subroutine (macro). Is that acceptable?
|