Find a lotto combination for a given CSN rank sequence index lexicographic, lexicographical order.

Mathematics of Combination Sequence Number (CSN) or Lexicographical Order (Index) – Heated Debates

By Ion Saliu, Programmer of Lexicographic Order Software

Users appreciate software program to calculate the lexicographic order of a lotto combination CSN.

Two algorithms in software to calculate the combination lexicographical order, or rank, or index.

Published on July 11, 2001 — last update September 2011.

• Apparently, the topic had been discussed for years. One formula was presented in newsgroups, especially rec.gambling.lottery. Many readers, without a deep mathematical analysis, had accepted it. Some still believe in that formula in a religious fashion.

Others put their personal pride above anything, regardless of proof or reasoning. There are situations when personae will not accept even well demonstrated common truths. You will have a hard time trying to convince personae that “10 + 7 = 17 in the decimal numerical system”.

Here are excerpts from newsgroups on the combination sequence number, CSN subject.



My congratulations to you on a terrific little lexicographic program that CORRECTLY calculates the CSN of any lotto number sequence and is also successful in reversing the process. As you point out below, the formula that has been kicking around here for a few years now is flawed and produces incorrect results. I believe it had its origins with an eccentric math "expert" from New Zealand named Don.

In spite of several other contributors (including myself) pointing this out, that formula continues to be trotted out by various people who, for one reason or another, refuse to accept that it is incorrect. Perhaps your efforts will finally put the issue to rest. Thank you for doing so.

Author: Lazarus

In article '', john Latala says...

: There is another change in NthIndex.EXE. The only problem I have with your algorithm is that it's kind of slow on my HP48 calculator. Just running a program which is a simple FOR loop to count from 1 to 14000000 lotto combinations takes a few hours. At least the other algorithms ran in a reasonable time.

At present I have a program that does CSN to set (i.e. {n1 n2 n3 n4 n5 n6}). For going from set to CSN I wrote a program that does a binary search in the CSN set until it hits the right one. It's not fast, about twenty seconds, but it does work.

• Why do you run it on a calculator? What are the PCs for?

As of your binary algorithm to calculate the CSN and vice versa. Is it the same that Royce Penny presented a while ago in the thread One for the math-heads? Please read my reply. Such a lexicographical order algorithm is incorrect IF it doesn't take into account the largest number in the lotto game. Such an algorithm leads to correct results ONLY in the very beginning of lotto sequences.

For example, combination 1 2 3 4 5 6 has an index (CSN) of 1 in all lotto-6 games. Maybe that's why the “CSN formula” was considered correct for that long. But a combination like 1 2 3 4 6 7 has different CSNs in different games. A lotto 49/6 game goes from 1 2 3 4 5 49 to the next combination: 1 2 3 4 6 7. In a lotto 54/6, the combination 1 2 3 4 5 49 is followed by:


then the combination:
1 2 3 4 6 7.

As you can see, 1 2 3 4 6 7 has different CSNs (indices) in the two lottery games.

Ion Saliu

Dick Adams -- The Wizard of Odds and sometimes Taxes too.

: C(5,48)+C(5,47)+C(5,46)+C(5,45) + ....

If that doesn't help you nothing will. :)

Dick - Johnny Walker Black Label works much better.

Do you think that I should tell him also that the formula would be:
CSN = C(n1-1,1)+C(n2-1,2)+C(n3-1,3)+C(n4-1,4)+C(n5-1,5)+C(n6-1,6)+1
where CSN is the Combination Sequence Number?
Or, should I keep it to myself??

Royce Penny
Royce Penny's Money Machine

• Dear Mr. Vice-President Dick “Quincy” Adams:
• Your Majesty King Lotto XLIX:

With all due respect, Your formulae are utterly incorrect.

Let's think of a simple combination, such as 1 2 3 4 5 8. What is its CSN? An absurd result, for there is no C(0,1), C(1,2), C(2,3), C(3,4), C(4,5); there can be only C(7,6).

Also importantly, the correct lexicographical formula should take into consideration differences in lotto games formats. One fundamental element of a lotto game format is its largest number. Thus, in a lotto 49/6 game, the CSN (combination sequence number) for combination 6 7 16 20 28 47 is 6,991,908 (exactly the mid-point in the combination set). The same combination 6 7 16 20 28 47 has an index (CSN) of 45,148,858 in a lotto 69/6 game (PA lottery). Your formulae do not lead to these results, the only mathematically correct results.

Although not a general-purpose formula, the lexicographic algorithm I presented a few days ago represents the easiest way to calculate the indexes of any lotto combinations. The algorithm is for the BASIC language, but it can be converted to any programming language. I compiled NthIndex.EXE with PowerBasic, especially because of increased speed of execution at the command prompt.

Ion Saliu

Hello Royce and Dick,
Strange as it apparently seems to some I too use the ID (index or CSN) in my lotto programs. In my attempts to produce a 46,6,3,3,759 lotto wheel, I calculate the ID for any 3 number combination and that helps keep track of which lotto combinations I have already covered. Using this technique and other programming "shortcuts" I have a program which can start producing 26,6,3,3,130 lotto wheels in about an hour.

I am not a mathematician and so I derived the logic for the code by just studying the data. It does however rely on a short loop and that means processing power. So the purpose of this email is to ask you to please explain the mathematical formulas mentioned as I don't understand the symbolism C(...) etc.

Again my math is very basic ... :)

• I suggest you drink two six packs of beer and then you won't care. For your mental block, I recommend medicinal discovery of the 20th century: Jack Daniels Black Label. Jack Black cures everything except alcoholism and for that you can go on a maintenance dose.

Dick -- The Wizard of Odds and sometimes Taxes too.

Ion -
As per your sig above, there is ”...nothing stronger than reason..." So...the number of sets of 1 number when you have 0 is 0, the number of sets of 2 numbers when you have 1 is 0, the number of sets of 3 numbers when you only have 2 is again 0, the number of sets of 4 numbers with only 3 available is 0, the number of sets of five numbers with only 4 on the table is also zero.

It is really that simple, unless you have a mental block, which, according to Dick, can be cured instantly with Jack Daniel's Black Label.

Royce Penny (Lotto-King) - Royce Penny's Money Machine


• To His Majesty King Lotto XLIX:

There are "kingdoms" in this world where the pupils are taught the combinatorial mathematics. The very first rule they learn is this:
“In combinations of N elements taken M at a time, M must be less than or equal to N.”
For it is absurd to try to combine 2 elements taken them 3 at a time, or 0 elements 6 at a time. If one has only 2 elements, how can one combine 3 of them at a time? Huh? One particular value that M can take is 0. C(N, 0) = 1

The number of combinations of any N elements taken 0 at a time is 1. But 0 elements taken N at a time is an absurdity, Super Crocodilule of Axiomatic Pursuits! I don't know if you still keep your school textbooks. I don't! I would like to refer you, however, to a book recognized in all kingdoms. It just deals with numbers. It compiles mathematical knowledge from various times and "kingdoms". The book is Warren Weaver's Lady Luck. It presents combinatorial analyses starting at page 92.

On the other hand, everybody has the right to set new knowledge, including new mathematics. You have a right to design a combinatorial algorithm with the following premise:
“If N is less than M, then the number of combinations is set to 0.”

I quote you again:
"So...the number of sets of 1 number when you have 0 is 0, the number of sets of 2 numbers when you have 1 is 0, the number of sets of 3 numbers when you only have 2 is again 0, the number of sets of 4 numbers with only 3 available is 0, the number of sets of five numbers with only 4 on the table is also zero."

Your indexing formula, however, is still bad:
CSN = C(n1-1,1)+C(n2-1,2)+C(n3-1,3)+C(n4-1,4)+C(n5-1,5)+C(n6-1,6)+1

What is CSN for combination 1 2 3 4 5 8?

According to your formula, CSN = 0 + 0 + 0 + 0 + 0 + C(7,6)+1 = 7 + 1 = 8.

In reality, CSN is 3:
1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 5 8
= i.e. CSN = 3.

Ultimately, LexicographicSets.EXE is the summit of all lexicographic . . . make it lexicographical ordering. The program finds (calculates) the index, or order, or rank, or numeral of all types of sets: exponents, permutations, arrangements, and combinations, including Powerball. Conversely, the program finds (constructs) the set for a given index, or order, or rank, or numeral. The sets are considered in sequential or lexicographic (lexicographical), or dictionary order.

Software to calculate the lexicographical order of a permutation combination – and vice versa.

I am afraid whisky in summer time in North America is a no-no. I consider also the divine wine to be a no-no in the hot season. May I recommend Cinzano on ice, with club soda and lemon?

The recipe is known as FFD3: Fundamental Formula of Drinking, the third season. DC in FFD# does not stand for degree of certainty as in FFG. In FFD3, DC stands for Divine Concentration.

À la nôtre! Cheers!

Ion Saliu

The Math of Combination sequence number or Lexicographical Order was hotly debated.

This is a comprehensive list of my writings on the topic of lexicographical order or indexing, including algorithms and software.

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 lotto software ever created. No kidding! Read the conditions to becoming a registered member: Download Great Free Software: Paid Membership Required.

Combinatorics is combinatorial mathematics to calculate combination rank, order, sequence number.

Download here software to find the lexicographical order of lotto combinations or CSN.

| Home | Search | New Writings | Odds, Generator | Contents | Forums | Sitemap |

We wrote software for lexicographic order indexing and combinations from lexicographical indexes.