 |

06-19-2002, 10:04 AM
|
 |
Centurion
|
|
Join Date: Mar 2002
Location: Puerto Rico
Posts: 174
|
|
Lotery wanna be
|
Hiya,
I need some help creating the logic for a lotery program. The professor assigned our group to create a "loto program" or better known as Lotery. The numbers are from 1 to 42. Which means I have 42 diffrent combinations right?(six options)(ej.12,32,45,65,67,43) The program has to create all the combinations available in a text file, but show a radom number from the combinations it created. please help!
I belive I have to multiply 42 * 42 = 1764 (combinations ej. 1,1,1,1,1,1 or 1,1,1,1,1,2) then have 1764 * 42  Im stuck....
THNX
koqui
|
__________________
--KoQuI--
|

06-19-2002, 10:07 AM
|
 |
ISearchGoogle
Retired Moderator * Expert *
|
|
Join Date: May 2001
Location: england
Posts: 6,321
|
|
One way of generating the various possibilities is via nested loops -
Code:
Private Sub Form_Load()
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 3
For j = 1 To 3
For k = 1 To 3
Text1.Text = Text1.Text & vbCrLf & i & "," & j & "," & k
Next k
Next j
Next i
End Sub
However, I can imagine this being mighty slow if you've got 42 variables...
|
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
|

06-19-2002, 10:15 AM
|
 |
ISearchGoogle
Retired Moderator * Expert *
|
|
Join Date: May 2001
Location: england
Posts: 6,321
|
|
In fact, I just tried it, and not only did it crash my machine, but the file it produced was over 18MB. Heh.. which also crashed my machine... 
|
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
|

06-19-2002, 10:16 AM
|
|
|
If you have 6 options and 42 variables, then i'm pretty sure that the formula for figuring out how many combinations there are is 42!/6! (42 factorial divided by 6 factorial). Am I correct on this? The nested loop would look like this:
Code:
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
For a = 1 to 42
For b = 1 to 42
For c = 1 to 42
For d = 1 to 42
For e = 1 to 42
For f = 1 to 42
List1.AddItem a & "." & b & "." & c & "." & d & "." & e & "." & f
Next f
Next e
Next d
Next c
Next b
Next a
This seems really inefficient though...I'm sure there is a better way, but at the moment, I can't think of a one.
---- UPDATE ----
I just remembered, it's 42!/(42-6)!, not 42!/6!
Therefore, there are.......................3776965920 combinations (if order DOES count), if order does not count, then you have to account for repeat combinations.... the formula for THAT is 42!/(6!(42-6)!), which is 5245786
|
Last edited by Apoc; 06-19-2002 at 10:32 AM.
|

06-19-2002, 10:20 AM
|
 |
ISearchGoogle
Retired Moderator * Expert *
|
|
Join Date: May 2001
Location: england
Posts: 6,321
|
|
Since there are 5,489,031,744 possible results, that many nested loops will nuke your system as I mentioned above. Placing DoEvents statements at the end of each loop saves the nuking, but it takes an _awful_ long time to work them all out.
Edit: I was just doing 42^6. Is that not right? It's been a while since I've done any maths... but no, in the lottery, order does not count - so you're probably right there. 
|
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
|

06-19-2002, 10:36 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
We have a lottery in Canada called 6/49 which is 6 numbers out of 49. It generates about 14 million possibilities so 5 million for 6/42 sounds about right.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

06-19-2002, 12:24 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Here is some code which should generate every possible combination in which order is not important and no number repeats.
Code:
Option Explicit
Private Sub Command1_Click()
Dim n&, s$
Dim d1%, d2%, d3%, d4%, d5%, d6%
n = 0
For d1 = 1 To 37
For d2 = d1 + 1 To 38
For d3 = d2 + 1 To 39
For d4 = d3 + 1 To 40
For d5 = d4 + 1 To 41
For d6 = d5 + 1 To 42
s = CStr(d1) & CStr(d2) & CStr(d3) & CStr(d4) & CStr(d5) & CStr(d6)
n = n + 1
Next d6
Next d5
Next d4
Next d3
Next d2
Next d1
Debug.Print n
End Sub
When I run it, I get a total of 5,245,786 values, so APOC is correct. Note that although I assign the number to s, I don't actually save it anywhere...you'll have to add the code for that yourself.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|