- Home
- Premium Memberships
- Lottery Results
- Forums
- Predictions
- Lottery Post Videos
- News
- Search Drawings
- Search Lottery Post
- Lottery Systems
- Lottery Charts
- Lottery Wheels
- Worldwide Jackpots
- Quick Picks
- On This Day in History
- Blogs
- Online Games
- Premium Features
- Contact Us
- Whitelist Lottery Post
- Rules
- Lottery Book Store
- Lottery Post Gift Shop
The time is now 6:03 am
You last visited
May 6, 2024, 4:10 am
All times shown are
Eastern Time (GMT-5:00)
Converting a number to a series, and a series to a number.Prev TopicNext Topic
-
Has any one ever heard of an algorithm that can turn a series of numbers from a set pool/set take into a number, or a number into a series for a given size pool and take?
Pool: 1-10 Take: 3 numbers (120 possible combinations)
ID#1 would be 1-2-3, and ID#120 would be 8,9,10...
-
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineQuote: Originally posted by Datapile on Jun 1, 2017
Has any one ever heard of an algorithm that can turn a series of numbers from a set pool/set take into a number, or a number into a series for a given size pool and take?
Pool: 1-10 Take: 3 numbers (120 possible combinations)
ID#1 would be 1-2-3, and ID#120 would be 8,9,10...
Yes we have, it's called the Combinatorial Index.
We created an Excel file for converting Combinations into Index Numbers and Index Numbers into Combinations.
http://www.jadexcode.com/Files/Excel/CombinatorialIndex.xlsm
or
ftp://www.jadexcode.com/Excel/CombinatorialIndex.xlsm
These are macro enabled.
This is an example of a Pick 6 of 49 conversion you'll see on the first sheet.
Index Value Index to Combination Combination Separated Combination to Index 1 01 02 03 04 05 06 1 2 3 4 5 6 1 2 01 02 03 04 05 07 1 2 3 4 5 7 2 3 01 02 03 04 05 08 1 2 3 4 5 8 3 400 01 02 03 04 15 20 1 2 3 4 15 20 400 500 01 02 03 04 18 24 1 2 3 4 18 24 500 600 01 02 03 04 21 37 1 2 3 4 21 37 600 7293487 06 10 22 33 45 47 6 10 22 33 45 47 7293487 13983816 44 45 46 47 48 49 44 45 46 47 48 49 13983816 7975767 07 08 24 38 39 44 7 8 24 38 39 44 7975767 8093333 07 10 12 23 25 30 7 10 12 23 25 30 8093333 4241622 03 14 15 19 24 42 3 14 15 19 24 42 4241622 7701802 06 18 23 32 43 45 6 18 23 32 43 45 7701802 3010463 02 17 18 22 44 45 2 17 18 22 44 45 3010463 1933103 02 04 10 11 12 21 2 4 10 11 12 21 1933103 9320058 08 19 20 30 32 41 8 19 20 30 32 41 9320058 11940609 13 22 24 25 44 48 13 22 24 25 44 48 11940609 3793525 03 08 11 37 40 46 3 8 11 37 40 46 3793525 11080648 11 20 21 22 23 42 11 20 21 22 23 42 11080648 3159829 02 22 29 31 42 47 2 22 29 31 42 47 3159829 7943967 07 08 16 20 35 49 7 8 16 20 35 49 7943967 8032333 07 09 15 29 30 47 7 9 15 29 30 47 8032333 8989527 08 12 13 22 30 46 8 12 13 22 30 46 8989527 12307374 14 24 40 43 45 49 14 24 40 43 45 49 12307374 7403070 06 12 15 26 27 32 6 12 15 26 27 32 7403070 9720456 09 13 15 27 37 43 9 13 15 27 37 43 9720456 794743 01 07 12 31 41 45 1 7 12 31 41 45 794743 5631014 04 17 28 35 43 47 4 17 28 35 43 47 5631014 8896728 08 10 24 25 26 33 8 10 24 25 26 33 8896728 12893370 17 18 24 27 31 49 17 18 24 27 31 49 12893370 2772731 02 12 17 27 34 39 2 12 17 27 34 39 2772731 1150041 01 11 13 28 36 41 1 11 13 28 36 41 1150041 3576126 03 06 11 19 21 29 3 6 11 19 21 29 3576126 403212 01 04 10 17 33 47 1 4 10 17 33 47 403212 12630872 15 32 33 43 44 47 15 32 33 43 44 47 12630872 13398034 20 21 25 26 36 42 20 21 25 26 36 42 13398034 290079 01 03 15 17 33 34 1 3 15 17 33 34 290079 9066427 08 13 16 22 31 38 8 13 16 22 31 38 9066427 980342 01 09 11 39 43 45 1 9 11 39 43 45 980342 9272359 08 17 24 30 37 41 8 17 24 30 37 41 9272359 4173589 03 12 27 38 41 46 3 12 27 38 41 46 4173589 5780380 04 24 29 35 40 48 4 24 29 35 40 48 5780380 11193781 11 27 32 33 36 47 11 27 32 33 36 47 11193781 11605645 12 24 39 42 44 47 12 24 39 42 44 47 11605645 10091654 09 24 37 39 40 48 9 24 37 39 40 48 10091654 9663890 09 12 16 18 27 46 9 12 16 18 27 46 9663890 13882365 26 38 42 45 46 49 26 38 42 45 46 49 13882365 11549079 12 21 25 30 36 49 12 21 25 30 36 49 11549079 9195459 08 15 24 30 35 46 8 15 24 30 35 46 9195459 1598138 01 21 23 31 33 49 1 21 23 31 33 49 1598138 Additional information on the functions are on the last sheet.
Function Information Note - integer refers to a mathematical integer {…, -3, -2, -1, 0, 1, 2, 3, …} =RandomLowerUpper(L, U) Returns - - An integer - A randomly selected integer in a set of integers ranging from L to U =Fact(N) Returns - - An integer - The factorial of N, mathematically written as ' N! ' - N! - N · (N - 1) · (N - 2) · … · 3 · 2 · 1 - 0! = 1 =Perm(N, R) Returns - - An integer - Using the Fact(N) function - The number of permutations in a pool of N numbers taken R at a time - (N! / (N - R)!) =Comb(N, R) Returns - - An integer - Using the Perm(N, R) and Fact(N) functions - The number of combinations in a pool of N numbers taken R at a time - (Perm(N, R) / Fact(R)) - (Perm(N, R) / R!) - ((N! / (N - R)!) / R!) - (N! / (R! · (N - R)!)) =Cdist(N, R, C, Z) Returns - - An integer - Using the Comb(N, R) function - The occurrence count of a number Z in a column C within a pool of N numbers taken R at a time - Comb((Z - 1), (C - 1)) · Comb((N - Z), (R - C)) - (((Z - 1)! / ((C - 1)! · (Z - 1 - (C - 1))!) · ((N - Z)! / ((R - C)! · (N - Z - (R - C))!))) - ((Z - 1)! · (N - Z)!) / ((C - 1)! · (Z - C)! · (R - C)! · (N - Z - R +C)!) =fColumnSum(N, R, Z) Returns - - An integer - Using the Cdist(N, R, C, Z) and Comb(N, R) functions - The sum of occurrence counts in the first column, 1, from the first number 1 to a number Z =Index2Combin(N, R, Index) Returns - - A string - Using the fColumnSum(N, R, Z) and Comb(N, R) functions - A Combination based on an Index in a pool of N numbers taken R at a time - 00's for an error condition =Combin2Index(N, R, Range) Returns - - An integer - Using the fColumnSum(N, R, Z) function - An Index value from a Combination within a pool of N numbers taken R at a time - A -1 for an error condition Variables and Array L - Least integer value in a set of intergers, all integer values U - Greatest integer value in a set of integers, all integer values N - Pool Size, positive integer R - Pick Size, positive integer C - Column, positive integer Z - Number, positive integer Index - A positive integer index value within a combination of N numbers taken R at a time Range - An array of positive integer values in ascending order left to right; in a single row containing a combination of N numbers taken R at a time The One Over None
I Know... -
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineThere are some limitations though that are more to do with your computers ability to handle large numbers.
We used a Double data type that can handle up to 1.79769313486232 ×10308 , however, it can only goto 15 decimal places on a 32-bit machine.
This would be a problem for a game like Keno 80/20 where there are 3,535,316,142,212,174,320 combinations, but Excel can only handle the first 15 digits and would show as 3,535,316,142,212,180,000.
You should be able to see the code for each of the functions by pressing Alt + F11 if your Excel is setup for Developer Mode.
The One Over None
I Know... -
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineIf you access the code you might be able to port it to a platform, language or machine that can handle more than a 15 decimal place precision.
The One Over None
I Know... -
I have created one that can. It is only limited by the speed of the processor and available memory. I will generate the sequence of any size or dimension you want. If you put the numbers you want in a array then run the algorithm It will run as an indexer and and create every possible combination within the given parameters. Generate all 2, 3, 3, 5, etc.\ combinations of the given numbers. So create all 11 million powerball combinations. Break every 5 digit set in to all of the 3, 4, 5 digit combinations. This is just one algorithm I have created for a program I have been writing. I am using dynamically sized code to allow it to process any lottery system when I am done. Running any number of probabilities, numbers count options or strategies to generate numbers sets. Let me know if anyone is interested in the algorithms or program it should be done soon. It is written in C, C# and run around a million numbers a second.
-
Very interesting... Both of you did something different than I did to end up at the same result.
FYI: Excel (no matter if its 32 or 64 bit) will truncate all numbers over 15 digits.
I ended up using Python- never truncates... built a 2 dimensional array with point values for 20/80 Keno.
For 3 numbers out of 1-10 it looks like this:
N1 N2 N3 1 0 0 0 2 28 7 1 3 49 13 2 4 64 18 3 5 74 22 4 6 80 25 5 7 83 27 6 8 84 28 7 The first column is 1-8, 2nd is 2-9, 3rd is 3-10. Combination must be in ascending order, with no duplicates. Add the 3 point values +1, and you have the ID number.
-
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineQuote: Originally posted by Datapile on Jun 2, 2017
Very interesting... Both of you did something different than I did to end up at the same result.
FYI: Excel (no matter if its 32 or 64 bit) will truncate all numbers over 15 digits.
I ended up using Python- never truncates... built a 2 dimensional array with point values for 20/80 Keno.
For 3 numbers out of 1-10 it looks like this:
N1 N2 N3 1 0 0 0 2 28 7 1 3 49 13 2 4 64 18 3 5 74 22 4 6 80 25 5 7 83 27 6 8 84 28 7 The first column is 1-8, 2nd is 2-9, 3rd is 3-10. Combination must be in ascending order, with no duplicates. Add the 3 point values +1, and you have the ID number.
Right-o about that Excel.
It's unfortunate the VB in Excel doesn't live up to its help.
The help section discusses the data types.
It describes a data type of Decimal; which, if it were actually available in Excel VB, it could handle the extra decimal places beyond 15.
The One Over None
I Know... -
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineThis is the VB Code used to transform from Combination to Index and back.
If the Double data type were a Decimal data type, the code would work for 80/20.
We know VB in Visual Studio will handle the Decimal data type.
The Combinatorial Index works by the Combinatorial Fractalization properties of combinations to determine the Index value directly without having to go through all the preceding combinations to find it.
You might need to view the link in Internet Explorer or Google Chrome to see the formatted text correctly.
____________________________________________________________________________________________________
Function Fact(ByVal N As Integer) As Double
If (N <= 1) Then
Fact = 1
Else
Fact = N * Fact(N - 1)
End If
End Function
Function Perm(ByVal N As Integer, ByVal R As Integer) As Double
Dim a As Integer
Dim b As Double
b = 1
If (N < R) Then
Perm = 0
Else
For a = (N - (R - 1)) To N
b = b * a
Next a
Perm = b
End If
End Function
Function Comb(ByVal N As Integer, ByVal R As Integer) As Double
If (N < R) Then
Comb = 0
Else
Comb = Perm(N, R) / Fact(R)
End If
End Function
Function Cdist(ByVal N As Integer, ByVal R As Integer, ByVal C As Integer, ByVal Z As Integer) As Double
If ((Z < C) Or (Z > (N - (R - C))) Or (Z > N) Or (C > R) Or (N < 1) Or (R < 1) Or (C < 1) Or (Z < 1)) Then
Cdist = 0
Else
Cdist = Comb((Z - 1), (C - 1)) * Comb((N - Z), (R - C))
End If
End Function
Function fColumnSum(ByVal N As Integer, ByVal R As Integer, ByVal Z As Integer) As Double
Dim a As Integer
Dim ColumnSum As Double
If (Z < 1) Then
fColumnSum = 0
ElseIf ((Z >= 1) And (Z < (N - (R - 1)))) Then
ColumnSum = 0
For a = 1 To Z
ColumnSum = ColumnSum + Cdist(N, R, 1, a)
Next a
fColumnSum = ColumnSum
ElseIf (Z >= (N - (R - 1))) Then
fColumnSum = Comb(N, R)
End If
End Function
Function Index2Combin(ByVal N As Integer, ByVal R As Integer, ByVal I As Long) As String
Dim a, b, Combination(), Z As Integer
Dim C, J As Long
ReDim Combination(R)
Dim tmpString, CombinFormat As String
Dim NumberFound As Boolean
tmpString = ""
CombinFormat = ""
C = Comb(N, R)
J = I
J = J - 1
Z = 0
b = Len(Format(N, "0"))
For a = 1 To b
CombinFormat = CombinFormat & "0"
Next a
For a = 1 To R
If ((I >= 1) And (I <= C)) Then
If (a = 1) Then
Combination(a) = 1
Else
Combination(a) = Combination(a - 1) + 1
End If
NumberFound = False
Do
Select Case (J - fColumnSum((N - Z), (R - (a - 1)), (Combination(a) - (Z + 1))))
Case Is < 0
Combination(a) = Combination(a) - 1
NumberFound = True
Case Is = 0
NumberFound = True
Case Is > 0
Combination(a) = Combination(a) + 1
End Select
Loop Until NumberFound
J = J - fColumnSum((N - Z), (R - (a - 1)), (Combination(a) - (Z + 1)))
Z = Combination(a)
Else
Combination(a) = 0
End If
tmpString = tmpString & Format(Combination(a), CombinFormat)
If (a < R) Then tmpString = tmpString & " "
Next a
Index2Combin = tmpString
End Function
Function Combin2Index(ByVal N As Integer, ByVal R As Integer, ByVal theRange As Range) As Double
Dim a As Integer
Dim fSum As Double
Dim NotInAscendingOrder, NotInPool As Boolean
NotInAscendingOrder = False
NotInPool = False
If ((theRange.Rows.Count <> 1) Or (theRange.Columns.Count <> R)) Then
Combin2Index = -1
Exit Function
End If
For a = 1 To R
If (a < R) Then
If (theRange.Cells(1, a) >= theRange.Cells(1, (a + 1))) Then
NotInAscendingOrder = True
End If
End If
If ((theRange.Cells(1, a) < 1) Or (theRange.Cells(1, a) > N)) Then
NotInPool = True
End If
Next a
If (NotInAscendingOrder Or NotInPool) Then
Combin2Index = -1
Exit Function
End If
fSum = 1
For a = 1 To R
If (a = 1) Then
fSum = fSum + fColumnSum(N, R, (theRange.Cells(1, 1) - 1))
Else
fSum = fSum + fColumnSum((N - theRange.Cells(1, (a - 1))), (R - (a - 1)), (theRange.Cells(1, a) - (theRange.Cells(1, (a - 1)) + 1)))
End If
Next a
Combin2Index = fSum
End Function
____________________________________________________________________________________________________The One Over None
I Know... -
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineIf you want to see all our previous posted topics, you can see them in our Shared Favorites section of our profile.
Either click on our name and select See JADELottery's shared favorites
Or
Use this Link https://www.lotterypost.com/member/1170/favorites
We like to keep our topics in an easy referenced place, in addition to others posted topics.
The One Over None
I Know... -
dah!! im taking a break!!
-
A random 20/1000 to index:
INDEX
332022691049562466559093563902057368214036N1-N20
173 179 221 272 286 324 352 357 384 418 451 515 536 577 600 665 672 674 755 942 -
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineThe One Over None
I Know... -
Here is a Java port of this code(line by line) :
package org.home.lottery.common.utilities;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class CombinatorialIndex {
private ArrayList<List<Integer>> allCombos = new ArrayList<List<Integer>>();
public static void main(String args[]) {
CombinatorialIndex ci = new CombinatorialIndex();
ci.setupData();
ci.print();
}
public void print() {
for ( List<Integer>combo:allCombos) {
BigDecimal combin2Index = Combin2Index(49, 6, combo);
System.out.println(combin2Index);
}
}
public void setupData() {
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,6}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,7}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,8}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,15,20}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,18,24}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,21,37}));
allCombos.add(Arrays.asList(new Integer[]{6,10,22,33,45,47}));
allCombos.add(Arrays.asList(new Integer[]{44,45,46,47,48,49}));
allCombos.add(Arrays.asList(new Integer[]{1,14,17,29,31,37}));
allCombos.add(Arrays.asList(new Integer[]{10,16,21,27,33,46}));
allCombos.add(Arrays.asList(new Integer[]{3,7,9,13,45,49}));
allCombos.add(Arrays.asList(new Integer[]{6,9,29,30,31,34}));
allCombos.add(Arrays.asList(new Integer[]{1,8,15,23,31,48}));
allCombos.add(Arrays.asList(new Integer[]{7,26,31,38,42,43}));
allCombos.add(Arrays.asList(new Integer[]{7,29,35,41,45,49}));
allCombos.add(Arrays.asList(new Integer[]{5,8,10,16,17,33}));
allCombos.add(Arrays.asList(new Integer[]{13,15,19,21,26,28}));
allCombos.add(Arrays.asList(new Integer[]{7,8,12,24,36,43}));
allCombos.add(Arrays.asList(new Integer[]{1,7,10,12,13,43}));
allCombos.add(Arrays.asList(new Integer[]{8,13,30,36,44,47}));
allCombos.add(Arrays.asList(new Integer[]{16,19,21,26,33,47}));
allCombos.add(Arrays.asList(new Integer[]{4,5,24,27,32,49}));
allCombos.add(Arrays.asList(new Integer[]{3,17,25,28,29,31}));
allCombos.add(Arrays.asList(new Integer[]{3,23,24,27,35,36}));
allCombos.add(Arrays.asList(new Integer[]{7,9,34,37,47,48}));
allCombos.add(Arrays.asList(new Integer[]{17,22,31,35,41,47}));
allCombos.add(Arrays.asList(new Integer[]{3,7,13,24,41,47}));
allCombos.add(Arrays.asList(new Integer[]{1,10,16,25,29,46}));
allCombos.add(Arrays.asList(new Integer[]{3,16,17,34,42,47}));
allCombos.add(Arrays.asList(new Integer[]{12,16,34,36,38,40}));
allCombos.add(Arrays.asList(new Integer[]{8,9,12,18,34,37}));
allCombos.add(Arrays.asList(new Integer[]{3,5,6,16,29,45}));
allCombos.add(Arrays.asList(new Integer[]{4,5,6,7,12,45}));
allCombos.add(Arrays.asList(new Integer[]{1,2,11,18,37,42}));
allCombos.add(Arrays.asList(new Integer[]{1,7,9,22,45,46}));
allCombos.add(Arrays.asList(new Integer[]{5,16,17,24,42,45}));
allCombos.add(Arrays.asList(new Integer[]{9,10,20,25,27,35}));
allCombos.add(Arrays.asList(new Integer[]{3,7,13,18,19,49}));
allCombos.add(Arrays.asList(new Integer[]{1,6,13,18,23,47}));
allCombos.add(Arrays.asList(new Integer[]{1,2,12,21,29,44}));
allCombos.add(Arrays.asList(new Integer[]{12,13,16,24,46,48}));
allCombos.add(Arrays.asList(new Integer[]{12,19,23,37,40,43}));
allCombos.add(Arrays.asList(new Integer[]{3,4,8,12,47,49}));
allCombos.add(Arrays.asList(new Integer[]{7,16,26,32,35,47}));
allCombos.add(Arrays.asList(new Integer[]{6,11,12,23,24,47}));
allCombos.add(Arrays.asList(new Integer[]{5,9,25,30,32,36}));
allCombos.add(Arrays.asList(new Integer[]{4,6,21,28,29,40}));
allCombos.add(Arrays.asList(new Integer[]{11,13,15,38,43,47}));
allCombos.add(Arrays.asList(new Integer[]{12,14,19,23,32,39}));
}
public BigDecimal Fact(Integer N) {
BigDecimal Fact;
if (N <= 1){
Fact = new BigDecimal(1);
} else {
Fact = new BigDecimal(N).multiply(Fact(N - 1));
}
return Fact;
}public BigDecimal Perm(Integer N, Integer R) {
Integer a;
BigDecimal b;
BigDecimal Perm;
b = new BigDecimal(1);
if(N < R) {
Perm = new BigDecimal(0);
}else {
for( a = (N - (R - 1)); a <= N; a++) {
b = b.multiply(new BigDecimal(a));
}
Perm = b;
}
return Perm;
}
public BigDecimal Comb(Integer N,Integer R) {
BigDecimal Comb;
if (N < R) {
Comb = new BigDecimal(0);
} else {
Comb = Perm(N, R).divide(Fact(R));
}
return Comb;
}public BigDecimal Cdist(Integer N, Integer R, Integer C, Integer Z) {
BigDecimal Cdist;
if ((Z < C) || (Z > (N - (R - C))) || (Z > N) || (C > R) || (N < 1) || (R < 1) || (C < 1) || (Z < 1)) {
Cdist = new BigDecimal(0);
} else {
Cdist = Comb((Z - 1), (C - 1)).multiply( Comb((N - Z), (R - C)));
}
return Cdist;
}public BigDecimal fColumnSum(Integer N, Integer R, Integer Z) {
//Integer a;
BigDecimal ColumnSum;
BigDecimal fColumnSum = null;
if (Z < 1) {
fColumnSum = new BigDecimal(0);
} else if ((Z >= 1) && (Z < (N - (R - 1)))) {
ColumnSum = new BigDecimal(0);
for(int a = 1; a <=Z; a++) {
ColumnSum = ColumnSum.add(Cdist(N, R, 1, a));
}
fColumnSum = ColumnSum;
}
else if (Z >= (N - (R - 1))) {
fColumnSum = Comb(N, R);
}
return fColumnSum;
}
public BigDecimal Combin2Index(Integer N, Integer R, List<Integer> combo) {
BigDecimal Combin2Index;
//Integer a;
BigDecimal fSum;
Boolean NotInAscendingOrder;
Boolean NotInPool;
NotInAscendingOrder = false;
NotInPool = false;
if(combo.size() != R) {
Combin2Index = new BigDecimal(-1);
return Combin2Index;
}
for(int a = 0; a < R-1; a++) {
if(a < R-1) {
if (combo.get(a) >= combo.get(a + 1)) {
NotInAscendingOrder = true;
}
}
if ((combo.get(a) < 1) || (combo.get(a) > N)) {
NotInPool = true;
}
}
if (NotInAscendingOrder || NotInPool) {
Combin2Index = new BigDecimal(-1);
return Combin2Index;
}
fSum = new BigDecimal(1);
for(int a = 0; a < R; a++) {
if (a == 0) {
fSum = fSum.add(fColumnSum(N, R, combo.get(a)-1));
} else {
fSum = fSum.add(fColumnSum((N - combo.get(a-1)), (R - a), (combo.get(a) - (combo.get(a - 1)) - 1)));
}
}
Combin2Index = fSum;
return Combin2Index;
}
}Note : the code is not yet re-factored(not even variables have been renamed...). Combination to index works perfectly. I am still porting Index to combination.
I used Debug.Print in each method in VBA and System.out.println in each method in Java. Both matched...
Thanks Jade.
-
Native American Eagle SunMN
United States
Member #21
December 7, 2001
4,812 Posts
OfflineQuote: Originally posted by thamizhpayan on Jun 6, 2017
Here is a Java port of this code(line by line) :
package org.home.lottery.common.utilities;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class CombinatorialIndex {
private ArrayList<List<Integer>> allCombos = new ArrayList<List<Integer>>();
public static void main(String args[]) {
CombinatorialIndex ci = new CombinatorialIndex();
ci.setupData();
ci.print();
}
public void print() {
for ( List<Integer>combo:allCombos) {
BigDecimal combin2Index = Combin2Index(49, 6, combo);
System.out.println(combin2Index);
}
}
public void setupData() {
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,6}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,7}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,5,8}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,15,20}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,18,24}));
allCombos.add(Arrays.asList(new Integer[]{1,2,3,4,21,37}));
allCombos.add(Arrays.asList(new Integer[]{6,10,22,33,45,47}));
allCombos.add(Arrays.asList(new Integer[]{44,45,46,47,48,49}));
allCombos.add(Arrays.asList(new Integer[]{1,14,17,29,31,37}));
allCombos.add(Arrays.asList(new Integer[]{10,16,21,27,33,46}));
allCombos.add(Arrays.asList(new Integer[]{3,7,9,13,45,49}));
allCombos.add(Arrays.asList(new Integer[]{6,9,29,30,31,34}));
allCombos.add(Arrays.asList(new Integer[]{1,8,15,23,31,48}));
allCombos.add(Arrays.asList(new Integer[]{7,26,31,38,42,43}));
allCombos.add(Arrays.asList(new Integer[]{7,29,35,41,45,49}));
allCombos.add(Arrays.asList(new Integer[]{5,8,10,16,17,33}));
allCombos.add(Arrays.asList(new Integer[]{13,15,19,21,26,28}));
allCombos.add(Arrays.asList(new Integer[]{7,8,12,24,36,43}));
allCombos.add(Arrays.asList(new Integer[]{1,7,10,12,13,43}));
allCombos.add(Arrays.asList(new Integer[]{8,13,30,36,44,47}));
allCombos.add(Arrays.asList(new Integer[]{16,19,21,26,33,47}));
allCombos.add(Arrays.asList(new Integer[]{4,5,24,27,32,49}));
allCombos.add(Arrays.asList(new Integer[]{3,17,25,28,29,31}));
allCombos.add(Arrays.asList(new Integer[]{3,23,24,27,35,36}));
allCombos.add(Arrays.asList(new Integer[]{7,9,34,37,47,48}));
allCombos.add(Arrays.asList(new Integer[]{17,22,31,35,41,47}));
allCombos.add(Arrays.asList(new Integer[]{3,7,13,24,41,47}));
allCombos.add(Arrays.asList(new Integer[]{1,10,16,25,29,46}));
allCombos.add(Arrays.asList(new Integer[]{3,16,17,34,42,47}));
allCombos.add(Arrays.asList(new Integer[]{12,16,34,36,38,40}));
allCombos.add(Arrays.asList(new Integer[]{8,9,12,18,34,37}));
allCombos.add(Arrays.asList(new Integer[]{3,5,6,16,29,45}));
allCombos.add(Arrays.asList(new Integer[]{4,5,6,7,12,45}));
allCombos.add(Arrays.asList(new Integer[]{1,2,11,18,37,42}));
allCombos.add(Arrays.asList(new Integer[]{1,7,9,22,45,46}));
allCombos.add(Arrays.asList(new Integer[]{5,16,17,24,42,45}));
allCombos.add(Arrays.asList(new Integer[]{9,10,20,25,27,35}));
allCombos.add(Arrays.asList(new Integer[]{3,7,13,18,19,49}));
allCombos.add(Arrays.asList(new Integer[]{1,6,13,18,23,47}));
allCombos.add(Arrays.asList(new Integer[]{1,2,12,21,29,44}));
allCombos.add(Arrays.asList(new Integer[]{12,13,16,24,46,48}));
allCombos.add(Arrays.asList(new Integer[]{12,19,23,37,40,43}));
allCombos.add(Arrays.asList(new Integer[]{3,4,8,12,47,49}));
allCombos.add(Arrays.asList(new Integer[]{7,16,26,32,35,47}));
allCombos.add(Arrays.asList(new Integer[]{6,11,12,23,24,47}));
allCombos.add(Arrays.asList(new Integer[]{5,9,25,30,32,36}));
allCombos.add(Arrays.asList(new Integer[]{4,6,21,28,29,40}));
allCombos.add(Arrays.asList(new Integer[]{11,13,15,38,43,47}));
allCombos.add(Arrays.asList(new Integer[]{12,14,19,23,32,39}));
}
public BigDecimal Fact(Integer N) {
BigDecimal Fact;
if (N <= 1){
Fact = new BigDecimal(1);
} else {
Fact = new BigDecimal(N).multiply(Fact(N - 1));
}
return Fact;
}public BigDecimal Perm(Integer N, Integer R) {
Integer a;
BigDecimal b;
BigDecimal Perm;
b = new BigDecimal(1);
if(N < R) {
Perm = new BigDecimal(0);
}else {
for( a = (N - (R - 1)); a <= N; a++) {
b = b.multiply(new BigDecimal(a));
}
Perm = b;
}
return Perm;
}
public BigDecimal Comb(Integer N,Integer R) {
BigDecimal Comb;
if (N < R) {
Comb = new BigDecimal(0);
} else {
Comb = Perm(N, R).divide(Fact(R));
}
return Comb;
}public BigDecimal Cdist(Integer N, Integer R, Integer C, Integer Z) {
BigDecimal Cdist;
if ((Z < C) || (Z > (N - (R - C))) || (Z > N) || (C > R) || (N < 1) || (R < 1) || (C < 1) || (Z < 1)) {
Cdist = new BigDecimal(0);
} else {
Cdist = Comb((Z - 1), (C - 1)).multiply( Comb((N - Z), (R - C)));
}
return Cdist;
}public BigDecimal fColumnSum(Integer N, Integer R, Integer Z) {
//Integer a;
BigDecimal ColumnSum;
BigDecimal fColumnSum = null;
if (Z < 1) {
fColumnSum = new BigDecimal(0);
} else if ((Z >= 1) && (Z < (N - (R - 1)))) {
ColumnSum = new BigDecimal(0);
for(int a = 1; a <=Z; a++) {
ColumnSum = ColumnSum.add(Cdist(N, R, 1, a));
}
fColumnSum = ColumnSum;
}
else if (Z >= (N - (R - 1))) {
fColumnSum = Comb(N, R);
}
return fColumnSum;
}
public BigDecimal Combin2Index(Integer N, Integer R, List<Integer> combo) {
BigDecimal Combin2Index;
//Integer a;
BigDecimal fSum;
Boolean NotInAscendingOrder;
Boolean NotInPool;
NotInAscendingOrder = false;
NotInPool = false;
if(combo.size() != R) {
Combin2Index = new BigDecimal(-1);
return Combin2Index;
}
for(int a = 0; a < R-1; a++) {
if(a < R-1) {
if (combo.get(a) >= combo.get(a + 1)) {
NotInAscendingOrder = true;
}
}
if ((combo.get(a) < 1) || (combo.get(a) > N)) {
NotInPool = true;
}
}
if (NotInAscendingOrder || NotInPool) {
Combin2Index = new BigDecimal(-1);
return Combin2Index;
}
fSum = new BigDecimal(1);
for(int a = 0; a < R; a++) {
if (a == 0) {
fSum = fSum.add(fColumnSum(N, R, combo.get(a)-1));
} else {
fSum = fSum.add(fColumnSum((N - combo.get(a-1)), (R - a), (combo.get(a) - (combo.get(a - 1)) - 1)));
}
}
Combin2Index = fSum;
return Combin2Index;
}
}Note : the code is not yet re-factored(not even variables have been renamed...). Combination to index works perfectly. I am still porting Index to combination.
I used Debug.Print in each method in VBA and System.out.println in each method in Java. Both matched...
Thanks Jade.
That's fantastic.
The One Over None
I Know... -
I used BigInteger. My methods are different too.