In an effort to mess around with Objects as well as calculate some statistics from the Louisiana Lottery, I converted a program I wrote to generate every possible Lottery number possible and then calculate how many prizes you would win and how much money you would win if you could buy every single combination of lottery tickets available. (just for the heck of it of course) So I modified it a bit in the process in an effort to make it more effiecient. I changed it to count backwards as that usually buys you a few extra cycles per loop. I also changed the main variables to use bit-type, but that was for a whole different reason that didn't work out.... Anyway, here's the code for Object Oriented folks to study....

Code:

#COMPILE EXE #DIM ALL TYPE LaLottoType n1 AS BIT * 6 IN DWORD n2 AS BIT * 6 n3 AS BIT * 6 n4 AS BIT * 6 n5 AS BIT * 6 n6 AS BIT * 6 IN WORD END TYPE UNION uLaLotto i AS LaLottoType d AS QUAD END UNION CLASS TLaLottery INSTANCE num AS uLaLotto INSTANCE tik() AS uLaLotto INSTANCE Valid AS DWORD INTERFACE iLaLottery INHERIT IUNKNOWN METHOD SortNumbers() DIM z(1 TO 6) AS BYTE DIM t AS INTEGER ARRAY ASSIGN z() = num.i.n1,num.i.n2,num.i.n3,num.i.n4,num.i.n5,num.i.n6 ARRAY SORT z() num.i.n1 = z(1) num.i.n2 = z(2) num.i.n3 = z(3) num.i.n4 = z(4) num.i.n5 = z(5) num.i.n6 = z(6) END METHOD METHODnts,eticket() AS STRING DIM s AS STRING 'me.SortNumbers() s = USING$("##",num.i.n1) + "," + USING$("##",num.i.n2) + "," + USING$("##",num.i.n3) + "," s = s + USING$("##",num.i.n4) + "," + USING$("##",num.i.n5) + "," + USING$("##",num.i.n6) METHOD = s END METHOD METHOD IsValidLottery() AS BYTE DIM tik(1 TO 10000000) AS uLaLotto DIM ex AS BYTE ex = -1 me.SortNumbers() IF (num.i.N1 < 1) OR (num.i.N2 < 1) OR (num.i.N3 < 1) OR (num.i.N4 < 1) OR (num.i.N5 < 1) OR (num.i.N6 < 1) THEN ex = 0 IF (num.i.N1 > 40) OR (num.i.N2 > 40) OR (num.i.N3 > 40) OR (num.i.N4 > 40) OR (num.i.N5 > 40) OR (num.i.N6 > 40) THEN ex = 0 IF (num.i.N1 = num.i.N2) OR (num.i.N1 = num.i.N3) OR (num.i.N1 = num.i.N4) OR (num.i.N1 = num.i.N5) OR (num.i.N1 = num.i.N6) THEN ex = 0 IF (num.i.N2 = num.i.N3) OR (num.i.N2 = num.i.N4) OR (num.i.N2 = num.i.N5) OR (num.i.N2 = num.i.N6) THEN ex = 0 IF (num.i.N3 = num.i.N4) OR (num.i.N3 = num.i.N5) OR (num.i.N3 = num.i.N6) THEN ex = 0 IF (num.i.N4 = num.i.N5) OR (num.i.N4 = num.i.N6) THEN ex = 0 IF (num.i.N5 = num.i.N6) THEN ex = 0 METHOD = ex END METHOD METHOD NumbersMatch(m1 AS BYTE, m2 AS BYTE, m3 AS BYTE, m4 AS BYTE, m5 AS BYTE, m6 AS BYTE) AS INTEGER DIM a1 AS BYTE DIM a2 AS BYTE DIM a3 AS BYTE DIM a4 AS BYTE DIM a5 AS BYTE DIM a6 AS BYTE DIM q(1 TO 6) AS BYTE DIM c AS INTEGER DIM rs AS INTEGER ARRAY ASSIGN q() = m1,m2,m3,m4,m5,m6 ARRAY SORT q() rs = 0 FOR c = 1 TO 6 IF (num.i.n1 = q(c)) THEN rs = rs + 1 IF (num.i.n2 = q(c)) THEN rs = rs + 1 IF (num.i.n3 = q(c)) THEN rs = rs + 1 IF (num.i.n4 = q(c)) THEN rs = rs + 1 IF (num.i.n5 = q(c)) THEN rs = rs + 1 IF (num.i.n6 = q(c)) THEN rs = rs + 1 NEXT c METHOD = rs END METHOD METHOD AllLotto DIM Tik(1 TO 10000000) AS uLaLotto DIM z AS QUAD DIM q AS QUAD DIM p AS uLaLotto DIM ex AS INTEGER DIM Valid AS QUAD DIM ticket AS QUAD DIM Winnings AS CURRENCY DIM w6 AS QUAD DIM w5 AS QUAD DIM w4 AS QUAD DIM w3 AS QUAD DIM a AS INTEGER DIM b AS INTEGER DIM c AS INTEGER DIM d AS INTEGER DIM e AS INTEGER DIM f AS INTEGER DIM winners AS QUAD Valid = 0 winners = 0 winnings = 0.00 w3 = 0 w4 = 0 w5 = 0 w6 = 0 CONSOLE SET SCREEN 25,80 PAGE 1,1 CLS FOR a = 40 TO 1 STEP -1 FOR b = 39 TO 1 STEP -1 FOR c = 38 TO 1 STEP -1 FOR d = 37 TO 1 STEP -1 FOR e = 36 TO 1 STEP -1 FOR f = 35 TO 1 STEP -1 num.i.n1 = a num.i.n2 = b num.i.n3 = c num.i.n4 = d num.i.n5 = e num.i.n6 = f me.SortNumbers() IF me.IsValidLottery() THEN PAGE 2,1 CLS ex = 0 INCR ticket IF (Valid < 1) THEN Tik(1) = num INCR Valid ELSE FOR q = 1 TO Valid IF Tik(q).d = num.d THEN ex = -1 NEXT q IF ex = 0 THEN INCR Valid Tik(Valid) = num LOCATE 3,1 COLOR 15 PRINT "Ticket # " + USING$("###,###,###,###",ticket) + " : "; COLOR 11 PRINT me.MakeTicket() + " " IF me.NumbersMatch(1,2,3,4,5,6) = 6 THEN COLOR 10 PRINT "JackPot!" Winnings = Winnings + 100000.00 INCR Winners INCR w6 END IF IF me.NumbersMatch(1,2,3,4,5,6) = 5 THEN COLOR 14 PRINT "$2,000.00" Winnings = Winnings + 2000.00 INCR Winners INCR w5 END IF IF me.NumbersMatch(1,2,3,4,5,6) = 4 THEN COLOR 9 PRINT "$50" Winnings = Winnings + 50.00 INCR Winners INCR w4 END IF IF me.NumbersMatch(1,2,3,4,5,6) = 3 THEN COLOR 12 PRINT "$3" Winnings = Winnings + 3.00 INCR Winners INCR w3 END IF IF me.NumbersMatch(1,2,3,4,5,6) < 3 THEN COLOR 13 PRINT "Looser!" END IF PRINT COLOR 10,0 PRINT "Winners : " + USING$("###,###,###,###",winners) PRINT "Winnings: " + USING$("###,###,###,###.##",winnings) PRINT "Match 3 : " + USING$("###,###,###,###",w3) PRINT "Match 4 : " + USING$("###,###,###,###",w4) PRINT "Match 5 : " + USING$("###,###,###,###",w5) PRINT "Match 6 : " + USING$("###,###,###,###",w6) PAGE 1,1 PCOPY 2,1 END IF END IF END IF PAGE 1,1 PCOPY 2,1 NEXT f NEXT e NEXT d NEXT c NEXT b NEXT a END METHOD END INTERFACE END CLASS FUNCTION PBMAIN () AS LONG DIM l AS iLaLottery &nle o LET l = CLASS "tLaLottery" CLS l.AllLotto() ' OPEN "Lottery.csv" FOR OUTPUT AS #1 ' PRINT #1, "n1,n2,n3,n4,n5,n6,matches,winnings" PRINT "Press any key to continue." WAITKEY$ END FUNCTION

## Comment