(Reposted from “The World Message board” at
http://www.saliu.com/bbs/)
• There has been a constant interest in this matter, especially
in the rec.gambling.lottery newsgroup. The question is: given a lotto
game, can we determine the combination for a particular index? For
example, the 49/6 lotto game has a total of 13,983,816 combinations.
The first combination (index 1) is 1-2-3-4-5-6. The last combination
in the set (index 13983816) is 44-45-46-47-48-49. Nick Koutras, a
lottery researcher with a keen interest in the scientific aspect of
the game, posted a link to a computer algorithm. The link is:
http://www.netlib.org/toms/
(file 515). The algorithm was developed by B. P. Buckles and M.
Lybanon. It can determine the lotto combination for a particular index
in standard lotto games. It cannot be used for PowerBall games,
without serious reworking.
The question above represents one half of the sphere. The other
hemisphere should answer the following question. “Given a lotto
combination, what is its index?” We already know the past
drawings in a lotto game. What indexes do the drawings represent? Are
most indexes located within the Gauss curve, around the median?
To me, this problem is like a chess problem. Instead of playing a
complete chess game, we, sometimes, get a break and solve chess
problems. “The white moves and check-mates in two.” There
is some intellectual value to this kind of problems, although the
practical value might be questioned.
Perhaps the original <I>B. P. Buckles and M. Lybanon</I> algorithm is
difficult to understand for most computer users. Plus, it can’t
answer the second question, without serious reworking. Instead, I use
a different algorithm that can be used to answer both questions and be
applied to PowerBall games as well. My algorithm is quick-and-dirty,
but much easier to understand. It can be used with minor modifications
to all types of lotto games. The only drawback would be speed of
execution. The B. P. Buckles and M. Lybanon algorithm answers the
first question instantly. My algorithm can take a few seconds,
sometimes half a minute for tough games, such as PowerBall 5/49/42, or
Pennsylvania 69/6. A better than Pentium II PC should run as fast as
the original algorithm.
The end result was NthIndex.EXE, a program I offer as freeware.
Location: my “FTP Download” site at:
www.saliu.com/infodown.html.
Here is my algorithm for a PowerBall-6 game.
Index# = 0
for A = 1 TO V -4
for B = A+1 TO V -3
for C = B+1 TO V -2
for D = C+1 TO V -1
for E = D+1 TO V
for F = 1 TO K
Index# = Index# + 1
IF Index# = L then 1001
Next F
Next E
Next D
Next C
Next B
Next A
1001 locate 12, 10
….
V represents the biggest of the first 5 powerball numbers. K
represents the biggest powerball number. L represents the index for
which a user wants to determine the corresponding combination.
If the combination is given and the user wants to determine the
corresponding index, only one line is changed. Index# represents a
counter. The line IF Index# = L then 1001 is replaced by:
IF A=NUM1 AND B=NUM2 AND C=NUM3 AND D=NUM4 AND E=NUM5 AND F=NUM6 THEN
2004
NUM1 to NUM5 represent the first 5 numbers of the combination the user
typed in. NUM6 represents the powerball. The only requirement is the
user type the combination in <I>ascending</I> order. If the drawings
in a data file are not sorted in ascending order, SORTING.EXE should
be run first. But most people can easily sort a drawing!
The algorithm is very fast because it does not use arrays, or disk
files.
The program saves the indexes to disk. The indexes are appended to
corresponding files. For example, INDEXES.6 for the lotto-6 game. A
user can determine the indexes for a large number of past drawings.
Then, s/he can load INDEXES.6 in an editor and see what indexes
already came out. The index range for past drawings does follow the
normal probability rule. I know what most people will do with the
results. Instead of selecting 6 or so lotto numbers, they will simply
select an index. “Ok. So index 34,245,621 already came out. I
think the next index will be 33,398,713. It hasn’t come out yet
and it’s located under the bell…”
Of course, LotWon is a ‘zillion times more versatile and
powerful. But a program like NTHINDEX.EXE can quench the intellectual
thirst of some people. I have known people who don’t play chess
but love to solve chess problems. Others don't play the lottery,
but love to develop or collect lotto wheels. And others don’t
play combinations but play indexes…
Best of luck!
Ion Saliu
-----------------------------------------------------------------------
• When you gotta do it, you’ll do it. For your mind won’t find peace until a
goal is reached.
I presented earlier this month of July 2001 an algorithm to calculate the index,
or rank, or lexicographical order, or combination sequence number (CSN). The
algorithm was 100% precise. It had one problem, however. The speed of execution
left much to be desired for monster-odds games, such as Keno (80/20, 70/20, even
70/10). The speed was acceptable for many other lotto games. Even a big game
such as the 49/5/42 PowerBall required less than half a minute to determine the
CSN. Nevertheless, running the algorithm for Keno games took an eternity!
I came back to the original “B.P. Buckles and M. Lybanon” algorithm (algorithm
“ACM #515”). I was able to add to it the reverse task: calculate the CSN for any
lotto game, but the PowerBall. Later, the PowerBall will be added to the
procedure.
I recompiled NTHINDEX.EXE to SEQUENCE.EXE, the program that uses the new
algorithm. The program is freeware at the download site:
http://www.saliu.com/infodown.html
Here is the main algorithm. Listed is also my function that calculates the
number of combinations ‘N taken M at a time’: Combine## (N, M).
The program SEQUENCE.EXE was compiled with PowerBasic for DOS.
‘ *** the new ‘combination index (rank)’ algorithm
‘ V = the biggest number in the lotto game (e.g. 49, or 80, etc.)
‘ K = numbers per combination (e.g. 6, 10, 20, etc.)
REDIM C(K)
REDIM Num(K) 'the numbers in the combination
LI## = 0
CSN## = 0
P1 = K - 1
FOR I = 1 TO P1
C(I) = 0
If I <> 1 THEN C(I) = C(I - 1)
2001 C(I) = C(I) + 1
R## = Combine##(V - C(I), K - I) 'call the combination calculator
LI## = LI## + R##
IF C(I) < Num(I) THEN GOTO 2001 ‘ the key command
LI## = LI## - R##
NEXT I
CSN## = LI## + Num(K) - Num(P1) 'combination sequence number
FUNCTION Combine##(N, M)
REM *** This function calculates the total number of combinations ***
REM *** 'N taken M' at a time
FA## = 1
FOR i = 1 TO M: FA## = FA## * i: NEXT i
va## = 1
FOR j = (N - M + 1) TO N: va## = va## * j: NEXT j
Combine## = va## / FA##
END FUNCTION
I verified the algorithm with many cases. I believe the procedure is 100%
accurate. But, if you think you discovered a miscalculation, please let me know.
Document the error as detailed and as clearly as possible. I believe I can fix
the errors – if any.
Ion Saliu
Return to Socrates
http://www.saliu.com/
Nothing stronger than Reason.
--------------------------------------------------------------------------------