In a Lotto Drawing, only certain number combinations are considered.
First, unlike a Pick game, no numbers are duplicated, so you have
five or six unique numbers that appear as a result, depending upon
how many balls are picked are per game. Although I know how to
determine how many separate plays would have to be used to play all
combinations, I wanted a program that would actually generate
those combinations.
I found I could do it readily enough with a series of embedded FOR
loops, one for each ball. Unfortunately, this means writting code
specific to either a five ball or six ball drawing. I wanted code
that could go either way.
It occurred to me that it might be possible to employ a reiterative
Sub or Function to get the same results. I've played with it all
afternoon, but it is proving more dificult than I expected. I
thought I would post the original code here as a challenge. I'm
sure someone will likely respond with a solution.
------------------
Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired
First, unlike a Pick game, no numbers are duplicated, so you have
five or six unique numbers that appear as a result, depending upon
how many balls are picked are per game. Although I know how to
determine how many separate plays would have to be used to play all
combinations, I wanted a program that would actually generate
those combinations.
I found I could do it readily enough with a series of embedded FOR
loops, one for each ball. Unfortunately, this means writting code
specific to either a five ball or six ball drawing. I wanted code
that could go either way.
It occurred to me that it might be possible to employ a reiterative
Sub or Function to get the same results. I've played with it all
afternoon, but it is proving more dificult than I expected. I
thought I would post the original code here as a challenge. I'm
sure someone will likely respond with a solution.
Code:
#COMPILE EXE #DIM ALL GLOBAL ns AS STRING GLOBAL panel AS STRING FUNCTION PBMAIN LOCAL a AS LONG, b AS LONG, c AS LONG, d AS LONG, e AS LONG, f AS LONG LOCAL g AS LONG, x AS LONG ns=STRING$(11,0) 'the pool of numbers to pick from FOR a=1 TO LEN(ns) MID$(ns,a)=CHR$(a) 'for convenience, numbered 1 to n in order NEXT panel=STRING$(6,0) 'the numbers picked for one panel 'There has to be a separate FOR loop for each pick. Here, the pick is 6: FOR a=1 TO LEN(ns) MID$(panel,1)=MID$(ns,a,1) 'update ther first ball FOR b=a+1 TO LEN(ns) MID$(panel,2)=MID$(ns,b,1) 'update the second ball FOR c=b+1 TO LEN(ns) MID$(panel,3)=MID$(ns,c,1) 'update the third ball FOR d=c+1 TO LEN(ns) MID$(panel,4)=MID$(ns,d,1) 'update the fourth ball FOR e=d+1 TO LEN(ns) MID$(panel,5)=MID$(ns,e,1) 'update the fifth ball FOR f=e+1 TO LEN(ns) MID$(panel,6)=MID$(ns,f,1) 'update the sixth ball INCR x PRINT x, 'track number of plays FOR g=1 TO LEN(panel) 'show the current panel PRINT FORMAT$(ASC(panel,g)," 00"); NEXT PRINT NEXT NEXT NEXT NEXT NEXT NEXT WAITKEY$ END FUNCTION
Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired
Comment