Curious as to the "real" number of possible draws (code help)

Hello all,


Sorry if I jumped into a wrong forum, as this is more to do with math and code, than actual lottery. Quick scan of forum sections didn't reveal a spot suitable for my question. So I am posting here.

Lotto stuff has always been awesome for learning programming, which is what I am doing to get my limited and extremely rusty vb6 knowledge up to speed and (actually) learn VB.NET. Of course hoping for a side benefit of a win sure helps with staring at textbooks.

The curious thing I ran across is this:

Everyone claims, and I am in full mathematical agreement that in a 6/49 lottery the number of possible draws is :

49!/(6!*(49 - 6)!) or 13,983,816

Now, what I have done is try to code a small app that will generate all of them. Pretty useless but that is irelevant to the issue.

The way I worked it, and I am a newbie at programming, is to simply go :

1-2-3-4-5-6
1-2-3-4-5-7
1-2-3-4-5-8
1-2-3-4-5-9
1-2-3-4-5-10
.....
1-2-3-4-5-48
1-2-3-4-5-49
1-2-3-4-6-7
etc

Notice the switch once i hit 49 the previous number goes +1 and the following go from previous+1 to 49 and so on.

This is the visual basic code for those who know how to code and can read - be gentle I am newb at this:

Code:
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
        Dim i As Long
        Dim n6 As Integer
        Dim n5 As Integer
        Dim n4 As Integer
        Dim n3 As Integer
        Dim n2 As Integer
        Dim n1 As Integer

		For n1 = 1 To 43
			For n2 = n1 + 1 To 44
                For n3 = n2 + 1 To 45
                    For n4 = n3 + 1 To 46
                        For n5 = n4 + 1 To 47
                            For n6 = n5 + 1 To 48
                                i += 1
                                My.Application.DoEvents()
                                Label1.Text = CStr(i & vbTab & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                                FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
                                PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                                FileClose(1)
                            Next n6
                            i += 1
                            My.Application.DoEvents()
                            FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
                            PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                            FileClose(1)
                        Next n5
                        i += 1
                        My.Application.DoEvents()
                        FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
                        PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                        FileClose(1)
                    Next n4
                    i += 1
                    My.Application.DoEvents()
                    FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
                    PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                    FileClose(1)
                Next n3
                i += 1
                My.Application.DoEvents()
                FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
                PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
                FileClose(1)
            Next n2
            i += 1
            My.Application.DoEvents()
            FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
            PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
            FileClose(1)
        Next n1
        i += 1
        My.Application.DoEvents()
        FileOpen(1, "c:/enumerated.txt", OpenMode.Append)
        PrintLine(1, i & "," & n1 & "," & n2 & "," & n3 & "," & n4 & "," & n5 & "," & n6)
		FileClose(1)
		Label1.Text = Label1.Text & vbtab & "done"
	End Sub

Here is the kicker.

i have tested this algorythm for say small sets - like 5 out of 8, and it works absolutely perfectly. All combinations are indeed written, enumerated and unique - no repeats.

However, once I actually plug in the 6 out of 49 the total number of possible outcomes is well above 13 million. In fact it stops at 44-45-46-47-48-49 and enumerates it as 10,068,347,520.

What i dont get is, I know the math is right, I think, and I should be getting 13 million and change, but I also seem to have done the nested loop properly as it works perfectly for smaller sets that I can verify by hand.

Whats going on here? Is my code wrong, or is the real number of possible combinations far above 13 mil? Every smaller set test of this snippet I have done has never generated any duplicates and has indeed generated every combination.
 

johnph77

Member
You are opening your text file after each integer. I believe it should only be necessary to do so after n6 changes value.

Also, your coding appears to be for a 6/48 matrix, not 6/49.

Originally I had this coded in and for QBASIC. This is what I used:


OPEN "T649.DAT" FOR OUTPUT AS #1
FOR A% = 1 TO 44
FOR B% = A% + 1 TO 45
FOR C% = B% + 1 TO 46
FOR D% = C% + 1 TO 47
FOR E% = D% + 1 TO 48
FOR F% = E% + 1 TO 49
N1& = N1& + 1
PRINT #1, USING "########"; N1&;
PRINT #1, USING "##"; A%; B%; C%; D%; E%; F%
NEXT F%
NEXT E%
NEXT D%
NEXT C%
NEXT B%
NEXT A%
CLOSE
END


Good luck,

John
 
I need to because otherwise the +1 that changes the lower limit of the next one wouldn't be written

curious again. I know the code is wrong now. I ran the exact same code from VB6 and it stopped at proper 13mil +.

Weird.

My guess is something must be reinitializing the loop after it has completed.

Anyway, since now this is definitely a code thing it no longer bellongs here, I thank you for your help.

Cheers
 

johnph77

Member
I've got text files with all possible draws, but they're rather large. With line numbers the file is 382Mb in size, without, 260Mb. They can be converted into ".csv" files suitable for import into MS Excel or any other spreadsheet program. But an Excel worksheet with all possible draws takes over 830Mb of space and requires nine pages.
 
No worries I got it to work. Its just a bit tougher to catch small logical or code errors after having "learned" vb6, not coding for couple of years and then facing a whole new language in .NET.

The file is indeed 300 some MB with line numbers but that is not an issue as I plan to filter it to smaller manageable size. After all it makes no sense for a draw to end up being 4,5,6,7,8,9 :)

Thanks.
 

Sidebar

Top