I am looking for a way to find all combinations of a 30 numbers in numbersArray
which has numbers between 0-1000.
For example 1st combination is: 0,1,2,3,4,5,6......29,30
For example 2nd combination is: 0,2,3,4,5,6,7......30,31
For example 2rd combination is: 0,3,4,5,6,7,8......31,32
Then continue to find all combinations. Any number must only appear once in the series of 30 numbers.
The very important detail here is if it is possible while create those combinations, then use them straight away. With other words, not storing the combinations first and then iterating through them again. Which would mean double amount of iterations?
Thank you!
void findcombinations()
{
//Declaring the array with 1000 indexes
//The number of indexes can be up to 100,000 indexes
int[] numbersArray = new int[1000];
for (int i = 0; i < numbersArray.Length; i++)
{
numbersArray[i] = i; //Assign number from 0-1000
}
//How to find all combinations of 30 numbers between: 0-1000?
//For example 1st combination is: 0,1,2,3,5,6,7......29,30
//For example 2nd combination is: 0,2,3,5,6,7,8......30,31
//For example 2rd combination is: 0,3,5,6,7,8,9......31,32
//How to dynamically find all combinations of a group of 30 numbers between 0-1000?
//Not perheps exactly use the below approach because that would mean that we already have filled the
//Array with the combinations.
//I am trying to see if there is a dynamic approach where the combinations are produced right away so
//They can be used straight away as they are produced?
int[,] allCombinations = new int[???,30]; ///??? How many combinations of 30 numbers
for (int i = 0; i < allCombinations.Length; i++)
{
for (int i2 = 0; i2 < allCombinations.GetLength(i); i2++)
{
//Do something with the combination of numbers here
}
}
}