lexicographic-order

Hoareau

Member
Hello


In Excel, the formula of GillesD

=COMBIN(49,6)-SI(44-C2>0,COMBIN(49-C2,6),0)-SI(45-D2>0,COMBIN(49-D2,5),0)-SI(46-E2>0,COMBIN(49-E2,4),0)-SI(47-F2>0,COMBIN(49-F2,3),0)-SI(48-G2>0,COMBIN(49-G2,2),0)-SI(49-H2>0,COMBIN(49-H2,1),0)


will give you the lexographic value for the 6 numbers placed in cells C2 to H2

How to make for 18 and 20 numbers With explanation PLEASE

Thank you
 

GillesD

Member
Lexographic value

Let's not take credit for things I did not develop. The formula was developped by somebody else although I used it in my postings. Sorry but I forgot who brought it up.

And about your question. I could probably adjust the formula to meet your request but there are two possibilities. Are you looking for:

1 - the lexographic values for 6 values out of 18 or 20?
- or -
2 - 18 or 20 numbers out of 49?
 

Hoareau

Member
thank you for your reply

Dana Delouis, that I thank, gave myself this macro, it gives the rank starting from the combination.

Function with:

combin(20;3)
combin(20;4)
combin(20;5)
combin(20;6)

If somebody test with other combinations and finds an error, to let me know


Function RankKSubset(Size, ParamArray v())
'//= = = = = = = = = = = = = = = = = =
'// By: Dana DeLouis
'//= = = = = = = = = = = = = = = = = =

Dim j As Long
Dim d As Double
Dim n As Double
Dim m As Double
Dim T As Double

With WorksheetFunction
m = Size
n = UBound(v) + 1
d = v(0)
T = T + .Combin(m, n) - .Combin(m - d + 1, n)
For j = 1 To UBound(v) - 1
m = m - d
n = n - 1
d = v(j) - v(j - 1)
T = T + .Combin(m, n) - .Combin(m - d + 1, n)
Next j
T = T + v(j) - v(j - 1)
End With
RankKSubset = T
End Function
 

Sidebar

Top