Lexicographic Index Numbers ( CSN ) Range

PAB

Member
GillesD Kindly Produced this Macro a while ago to List ALL Combinations for a 649 Lotto :-

Option Explicit
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer
Dim N As Long
Sub Combinations()
Range("A1").Select
Application.ScreenUpdating = False
N = 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
N = N + 1
ActiveCell.Value = A & "-" & B & "-" & C & "-" & D & "-" & E & "-" & F
ActiveCell.Offset(1, 0).Select
Next F
Next E
Next D
Next C
Next B
Next A
Application.ScreenUpdating = True
End Sub

I would like to be Able to Put a Range ( Using an "IF" Statement ) of Lexicographic Index Numbers, so that if a Combination is Within that Range it will be Accepted, and if a Combination is Outside that Range it will be Ignored.
So Basically, as it Runs through the Macro it Checks if the Lexicographic Number of that Combination is Within the Range Set.

Something Like ( as a Sequential Call ) :-
If LexNumber > 22500 And LexNumber < 50000 Then

Function :-
Function LexNumber()
LexNumber = False
*Code Will Go Here* Then
LexNumber = True
End Function

If we were to Use an Excel Formula for Example to do this ( For a Combination of 6 Numbers in Cells O14:T14 ) it would be :-
=COMBIN(49,6)-IF(44-O14>0,COMBIN(49-O14,6),0)-IF(45-P14>0,COMBIN(49-P14,5),0)-IF(46-Q14>0,COMBIN(49-Q14,4),0)-IF(47-R14>0,COMBIN(49-R14,3),0)-IF(48-S14>0,COMBIN(49-S14,2),0)-IF(49-T14>0,COMBIN(49-T14,1),0)

Any Help would be Appreciated.

All the Best
PAB
:wavey:
 

hot4

Member
I don't know if excel allows you to put the maximum value of A,B,C,D... as a variable yet initialized.
For example, when it states "For A = 1 To 44" if excel accepts

Max_A= 12;
For A = 1 To MAX_A

it would be easy for you to decompose the minimum lexicographic order and the maximum lexicographic order.

Ther's a formula that tells you that the Lex_order 22500 is the line A,B,C,D,E,F and that the Lex_Order 50000 is A', B', C', D', E', F' ; with this values you can state the For Next cicles like this:

For A = A'' To A'
For B = A + 1 To B'
For C = B + 1 To C'
For D = C + 1 To D'
For E = D + 1 To E'
For F = E + 1 To F'
N = N + 1
ActiveCell.Value = A & "-" & B & "-" & C & "-" & D & "-" & E & "-" & F
ActiveCell.Offset(1, 0).Select
Next F
Next E
Next D
Next C
Next B
Next A

:agree2:
 

GillesD

Member
Lexographic values

As johnph77 pointed out, the value N acts as a counter and represents the lexographic value for numbers A, B, C, D, E and F.

So you can use it in an IF ... THEN ... ENDIF loop to control whatever action you want to take depending on a given lexographic value.
 

PAB

Member
Thanks for the Replies :agree2: .
I am Still Not Sure GillesD how to Incorporate this into a Function though. I have Several Functions ( Using "If ... Then" ) Already which Run Within the Macro.

All the Best
PAB
:wavey:
 

hot4

Member
Re: Lexographic values

GillesD said:
As johnph77 pointed out, the value N acts as a counter and represents the lexographic value for numbers A, B, C, D, E and F.

So you can use it in an IF ... THEN ... ENDIF loop to control whatever action you want to take depending on a given lexographic value.

Yes, that's right GillesD.
However, if time is important here, the macro runs faster after selecting the interval between both lexicographic orders.
 

Ceryboy

Member
I,m a new member. All I know, I have a macro that generates the winning combinations and it is different to your macro.
 

PAB

Member
Hi Ceryboy,

Welcome to the Board. You will Find MANY Ideas and Strategies here, the Members are VERY Knowledgable and Helpful :agree: .

Perhaps you could Post your Macro for us to have a Look at Please.

All the Best
PAB
:wavey:
 

Sidebar

Top