Play about on a spreadsheet.
The following is taken from the above links. Original poster GillesD.
-------------------------------------------------------------------------------------------
The following formula works fine for a 6/49 lottery:
=COMBIN(49,6)-IF(44-N1>0,COMBIN(49-N1,6),0)-IF(45-N2>0,COMBIN(49-N2,5),0)-IF(46-N3>0,COMBIN(49-N3,4),0)-IF(47-N4>0,COMBIN(49-N4,3),0)-IF(48-N5>0,COMBIN(49-N5,2),0)-IF(49-N6>0,COMBIN(49-N6,1),0)
where N1, N2 ... N6 are the respective numbers (in ascending order) you want the lex number. You can also replace these values by a reference to cells where they are in a sheet.
------------------------------------------------------------------------------------
And going the other way from a Lex back to numbers......
The following macro does the job. It just goes through all combinations until it reaches the lex value that is entered in cell A1. It then places the numbers N1 to N6 in cells B1 to G1.
A formula might be faster and more elegant but brute force does the job here while we come up with something.
Listing for the macro LexToNumbers:
Option Explicit
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer
Dim nVal As Double, nLex As Double
Sub LexToNumbers()
nVal = Range("A1").Value
nLex = 0
For A = 1 To 44
For B = A + 1 To 45
For C = B + 1 To 46
For D = C + 1 To 47
For E = D + 1 To 48
For F = E + 1 To 49
nLex = nLex + 1
If nLex = nVal Then
Range("B1").Value = A
Range("C1").Value = B
Range("D1").Value = C
Range("E1").Value = D
Range("F1").Value = E
Range("G1").Value = F
Exit Sub
End If
Next F
Next E
Next D
Next C
Next B
Next A
End Sub
M
---------------------------------------------------------------------
Have a play with it...Pick some changeover numbers like
23 ,27,43 ,47,48 ,49 and get the lex.
Then try 23,27,43,46,47,48 and get the lex
theres a difference of 3 in the Lex value.
Remember numbers, because they have to be sorted in order and sit in their ordered positions, they are 'locked' by the rule that sets a maximum value of 44 in position 1, 45 in position 2, 46 in position 3, 47 in position 4, 48 in position 5 and 49 in position 6. Any attempted increment in Lex forces the digits to revert to the rules I set above, whilst flipping to the lowest allowable rightmost digits still keeping the balls in their order.