## 3 replies

Last post Aug 12, 2017 04:54 PM by saffy

• saffy

Member

157 Points

507 Posts

### Can we save Current state of Permutation combinations value

Hello Friends,

https://forums.asp.net/t/2126496.aspx?Multidimentional+Array+Permutation

We are able to generate multiple combinations of Multi dimensional array

also with the help of recursive logic we were able to generate combinations of given String.

But our requirement:

In any pattern using Multi dimensional or recursive logic or other. Can we store current value and continue next value when required?

We are able to achieve by checking/validating existing value from DB but, it hit performance.

e.g:

If by Multi dimensional

string[,] employees = new string[,]{

{"a", "b","c"},

{"a","b","c"},

{"a","b","c"};

E.g: a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa,

Save aaa value and generate next value when required. Next value aba and next value aca....

Or any other way.....

• Eric Du

Contributor

6680 Points

2715 Posts

### Re: Can we save Current state of Permutation combinations value

Aug 11, 2017 09:48 AM|Eric Du|LINK

Hi saffy,

According to your description and needs, I think you could 'remember' the index of this value. Then trigger this again from this index. For more details, please refer to this sample:

Sample Code:

```static void Main(string[] args)
{
string breakvalue = "";
string[,] employees = new string[,] { { "a", "b", "c" }, { "a", "b", "c" }, { "a", "b", "c" } };
Dictionary<string, string> result2 = new Dictionary<string, string>();
List<string> result = new List<string>();
int x = 0, y = -1, z = -1;
//x = 1;
//y = 1;
//z = 1;
while (true)
{
if (y > -1)
{
if (z > -1)
{
result.Add(employees[0, x] + employees[0, y] + employees[0, z]);
}
else
{
}
}
else
{
}
x++;
if (x > 2)
{
x = 0;
y++;
}
if (y > 2)
{
y = 0;
z++;
}
if (z > 2)
{
break;
}
}
foreach (var r in result)
{
Console.WriteLine(r);
breakvalue = r;
if (r == "aaa")
{
break;
}
}

string inputNumber = breakvalue;
int d;
int e;
int f;

if (inputNumber[0] == 'a')
{
d = 1;
}
else if (inputNumber[0] == 'b')
{
d = 2;
}
else
{
d = 3;
};

if (inputNumber[1] == 'a')
{
e = 1;
}
else if (inputNumber[1] == 'b')
{
e = 2;
}
else
{
e = 3;
};

if (inputNumber[2] == 'a')
{
f = 1;
}
else if (inputNumber[2] == 'b')
{
f = 2;
}
else
{
f = 3;
};

List<string> newresult = new List<string>();

while (true)
{
if (e > -1)
{
if (f > -1)
{
newresult.Add(employees[0, d] + employees[0, e] + employees[0, f]);
}
else
{
}
}
else
{
}
d++;
if (d > 2)
{
d = 0;
e++;
}
if (e > 2)
{
e = 0;
f++;
}
if (f > 2)
{
break;
}
}
for (int i = newresult.Count - 1; i >= 0; i--)
{
Console.WriteLine(newresult[i]);
}
}
```

Best Regards,

Eric Du

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• saffy

Member

157 Points

507 Posts

### Re: Can we save Current state of Permutation combinations value

Will implement and update back the status.

• saffy

Member

157 Points

507 Posts