Written by Ion Saliu on July 23, 2001.
• 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 software download site.
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.
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
' *** 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
This is a comprehensive list of my writings on the topic of lexicographical order or indexing, including algorithms and software.
The following are older and somehow outdated materials I wrote on lexicographical order subjects. Most of the older software is outdated. Nothing (in the whole world) can beat LexicographicSets.EXE or DrawIndex.EXE. Sentimentalism is good only to a close extent.
Of course, everybody loves to feast on great software, especially when it is free! My combinatorics software (and other categories) is absolutely free to run, for an unlimited period of time. However, only the registered members have a right to download the software. Membership requires a nominal fee — the most reasonable there is to connect to the greatest and most useful software ever created. No kidding! Read the conditions to becoming a registered member: Download Great Free Software: Paid Membership Required.