# Calculate Lexicographic Order of Permutations, Lotto Combinations, Powerball, Mega Millions, Euromillions

## By Ion Saliu, Developer of Lexicographical Ordering Software

Published on September 27, 2007.

LexicographicSets ~ Lexicographical ordering software.
DrawIndex ~ Lottery and combinatorial software.

I wrote previously about the lexicographical order. I wrote also software to calculate (find) indexes (ranks) and corresponding combinations. This page shows at the end related articles at this web site and previous software I wrote (freeware).

I realize now how much interest there is out there in lexicographic order field. I thought I had received way too many emails on the subject. But that amounts to almost nothing compared to what's on the Internet! I noticed that the keyword 'lexicographical' directs quite a few visitors to my site. Checking at Google and Yahoo, the keyword ranks my site pretty high. My site should always rank the highest, however!

One fact for sure: I make the matter intuitive. I link the lexicographic order issues (combinatorics in general) to real life. Then, I throw in the mix a most useful utensil: Software. Jargon might be unavoidable at times, but I always try to keep it clear. Look what you can read at an online encyclopedia:

In mathematics, the lexicographic or lexicographical order, (also known as dictionary order, alphabetic order or lexicographic(al) product), is a natural order structure of the Cartesian product of two ordered sets.
Given two partially ordered sets A and B, the lexicographical order on the Cartesian product A × B is defined as (a,b) = (a',b') if and only if a less than a' or (a = a' and b = b').
The result is a partial order. If A and B are totally ordered, then the result is a total order also.
More generally, one can define the lexicographic order on the Cartesian product of n ordered sets, on the Cartesian product of a countably infinite family of ordered sets, and on the union of such sets.

No wonder so many people run away in fear when they hear lexicographical order or combinatorics! Don't worry, fellas! It's not a form of an authoritarian régime!

Everything is composed of elements. The elements can be numerical (numbers), alphabetical (letters, words), or alphanumerical (both words and numbers). We can arrange the elements in four strictly ordered ways:
~ the set can have duplicate elements: exponents or Ion Saliu's sets;
~ N unique elements: permutations;
~ N unique elements in groups of M unique elements: arrangements (M less than or equal to N);
~ N unique elements in groups of M elements in ascending order: combinations (M less than or equal to N).

We can generate all possible sets via algorithms. Algorithms can also determine the index or lexicographical order of any element — without the need to generate the sets first.

An example of exponents (N=3, M=3): 111,112,113,121,122,123,131,132, etc. (a total of 27 sets, or 3 ^ 3).
The index of set (1,2,2) = 5.
The set for index = 4 is: (1,2,1).

An example of permutations (for N = 3): 1 2 3, 1 3 2, 2 1 3, 2 3 1, 3 1 2, 3 2 1, (a total of 6 sets or 3!).
The index of set (3,1,2) = 5.
The set for index = 4 is: (2,3,1).

An example of arrangements (for N = 3, M = 2): 1 2, 1 3, 2 1, 2 3, 3 1, 3 2 ( (a total of 6 sets, or 3 * 2).
The index of set (2,3) = 4.
The set for index = 5 is: (3,1).

An example of combinations (for N = 3, M = 2): 1 2, 1 3, 2 3 (a total of 3 sets, or 3! / 2!).
The index of set (2,3) = 3.
The set for index = 2 is: (1,3).

Writing software to automatically calculate the lexicographical order or index for a set — and vice versa — is extremely attractive to a large number of computer programmers and scientists. I find myself in that category of human beings — but with a twist. I have succeeded to write software that does the precise calculations for all four sets — and then some.

My software LexicographicSets calculates all the above, plus special-purpose or derived sets, such as Powerball, Mega Millions combinations, Euromillions combinations and two-in-one generalized lotto games.

The main menu of this much sought-after mathematical application:

Each module consists of two functions:
~ 1: Find Index Of Combination;
~ 2: Find Combination For Index.

I saw newsgroups postings from the early 1980s. It didn't look to me that the issue had been ever solved. I mean, I couldn't find the "mother of all sets generating"; or the "mother of all lexicographical indexes"! That finding corroborated with the requests I have received to write specific lexicographical indexing and generating software. I've been unable to find comprehensive software to tackle sets generating and lexicographic indexing. I assume, actually I bet big, that the software I wrote represents the most comprehensive answer to sets generating and lexicographic indexing.

The accuracy is also a very important issue. From what I was able to read, there has been a lot of bickering in the newsgroups. It appears that many attempts to tackle the job resulted in faulty algorithms and/or software. I can guarantee that my (comprehensive) software is fault-free to a very high degree. I haven't been able to find a wrong result in many, many tests (as of this writing, September 2007). I make this statement in lieu of an oath. LexicographicSets and DrawIndex represent error-free software for all intents and purposes.

I went two steps further. I added a highly requested function: Euromillions. This a fairly new lotto game played in some of the European countries that are part of the so-called Euro zone (except for United Kingdom, which does not use Euro as its currency).

Euromillions (Euromillones in Spanish, Euromilhoes in Portuguese) is a form of two-games-in-one lotto. There are two drawing chambers. They draw 5 numbers from the first drawing chamber. Then they draw 2 numbers from the second chamber (known as star numbers). The two chambers are independent. Thus, the numbers drawn from the second chamber can be equal to any of the numbers drawn from the first machine. It is possible to have Euromillions drawings such as this one (hypothetical):
1 6 29 33 50 1 6

The G module — Generalized 2-Game Lotto — expands the concept. There can be any two-in-one lotto games; e.g. drawing 6 of 49 from the first chamber, and 5 of 50 from the second drawing machine. This module can also help with the analysis of two independent lotto games; e.g UK 6/49 and Pennsylvania 6/49.

DrawIndex brings much more to the table. It calculates the lexicographic indexes for every combination (draw) in a lotto results file. The menu is similar to what LexicographicSets has to offer, except that makes lotto and horse racing trifectas discreet cases.

The reports show a huge preponderance of combinations coming from the FFG median zone. Brings more fuel to the arguing fire regarding the frequency or lack thereof for lotto combinations such as 1,2,3,4,5,6. As I made it compellingly clear, the standard deviation rules! The Standard Deviation is the strictly-on-alert watchdog that serves at the pleasure of Randomness Almighty.

You know, think of this simple but truthful fact. There have been hundreds of thousands of lotto drawings worldwide. We should have seen by now several, not just one, lotto combinations such as the infamous 1 2 3 4 5 6. We ain't seen any single one in this great world of ours. You asked me for an inch and I'll gladly give you a mile. I expand the 1-2-3-4-5-6 concept to 1 to 12 range of consecutive numbers. We should have seen THOUSANDS of lotto drawings (combinations) comprised of numbers from 1 to 12 only. We ain't seen a single one — not one lotto combination like 1 2 3 4 5 12! It would take a number of...infinities for that to happen!

Look also in the entire Universe for geometric or perfect shapes, such as lines, circles, spheres, pyramids. Such shapes have equal probabilities of appearance as any other shapes (those beautiful random shapes that adorn the Universe). We haven't seen any perfect or geometrical shape so far, searching all the way to the time and space of the Big Bang. No perfect shapes, except for those approximations created by the humans on Earth. This is a falsity for those walking on mental crotches: On earth as it is in heaven. Beauty is in the eyes of the beholder. There are no eyes in heaven...

### Essential Resources In Lexicographic (Lexicographical) Order and Indexing

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

Read Ion Saliu's first book in print: Probability Theory, Live!
~ Founded on valuable mathematical discoveries with a wide range of scientific applications, including the organic connection between probability theory and lexicographical ordering of numerical sets or word sets.

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.