Hi,
I have an issue with creating all possible outcomes for variable sequence of numbers.
For example, if i have 3 branches with 5, 7 and 9 values respectively, how do i create all possible combinations within each branch? The amount of numbers in each branch is different.
If so the values are treated as text and just concatenated? Why is there no 357? Why does the 3 come after the 57 in the last branch instead of before?
The idea is that in a branch which has x amount of values i find all of the combinations of numbers that are next to each other. In this example i would not need (37,5). The values that are not close, for example in a branch (1,2,3,4), i would not need combinations (13,2,4) and (1,24,3), however (123,4) and (1,234) would work.
In short all combinations except the ones that aren’t next to each other.
At the moment it doesn’t matter if the combinations are placed in one or separate branches.
private void RunScript(List<string> E, ref object P)
{
var permutations = new List<string>();
int n = E.Count;
int pow = (int) Math.Pow(2, n - 1);
for (int pattern = 0; pattern < pow; pattern++)
{
string binary = Convert.ToString(pattern, 2);
binary = new string('0', n) + binary;
binary = binary.Substring(binary.Length - n + 1);
var permutation = string.Empty;
for (int i = 0; i < n; i++)
{
permutation += E[i];
if (i < n - 1)
if (binary[i] == '0')
permutation += ",";
}
permutations.Add(permutation);
}
P = permutations;
}
the basic idea is to create all the binary numbers up to 2^{n-1} where n is the number of elements in your initial list. So let’s say 0000, 0001, 0010, 0011, 0100, 0101, … Whenever there’s a zero we want a comma, whenever there’s a one we just want to glue the two elements together. We need to ditch the last digit as commas after the last element are not wanted. Then zip through the two collections and compose those textual sequences… I’m sure there’s a much neater solution, but I can’t think of one right now.