# Generator of all possible N symbols strings

After searching the net for a solution to generate of all possible combination of N symbols from given strings, I decide to write one in python.

This is an algorithm for Permutation Generation you can run it from the beginning of the permutation or start it in the middle.

The algorithm is flexible and can handle any password length for given an “alphabet”

The variables:

characters = “abc” #  this will define the alphabet to generate the combination
letter = 3 # This will define how many combination of letters you want to have? the algorithm will start from 1 to the number you choose here.

Run Example:

characters = “ab12”
letter = 2;

Output:

a
b
1
2
aa
ba
1a
2a
ab
bb
1b
2b
a1
b1
11
21
a2
b2
12
22
aaa
baa
1aa
2aa
aba
bba
1ba
2ba
a1a
b1a
11a
21a
a2a
b2a
12a
22a
aab
bab
1ab
2ab
abb
bbb
1bb
2bb
a1b
b1b
11b
21b
a2b
b2b
12b
22b
aa1
ba1
1a1
2a1
ab1
bb1
1b1
2b1
a11
b11
111
211
a21
b21
121
221
aa2
ba2
1a2
2a2
ab2
bb2
1b2
2b2
a12
b12
112
212
a22
b22
122
222

Run Example:

characters = “abc123”
letter = 3;

Output:

a
b
1
2
aa
ba
1a
2a
ab
bb
1b
2b
a1
b1
11
21
a2
b2
12
22
aaa
baa
1aa
2aa
aba
bba
1ba
2ba
a1a
b1a
11a
21a
a2a
b2a
12a
22a
aab
bab
1ab
2ab
abb
bbb
1bb
2bb
a1b
b1b
11b
21b
a2b
b2b
12b
22b
aa1
ba1
1a1
2a1
ab1
bb1
1b1
2b1
a11
b11
111
211
a21
b21
121
221
aa2
ba2
1a2
2a2
ab2
bb2
1b2
2b2
a12
b12
112
212
a22
b22
122
222

# Benchmark Between to Methods that Resize Array in C#

Prob: There is two methods to change size of array in C#. Using a template of a Benchmark program from this informative site, I checked the two ways:

Array.Resize  VS  Array.CopyTo VS Loop

Conclusion: sometime build it your self is not that better then using the build-in commands…

Array.Resize took 30253 ms
Arryay.CopyTo took 29649 ms
Loop took 58323 ms

Solution:

Here is the code that I use

class Program
{
public static void AddCell1(ref double[] vector,int num)
{
int size = vector.Length;
Array.Resize(ref vector,size+1);
vector[size] = num;
}
//————————————————-

public static void AddCell2(ref double[] vector,int num)
{
double[] tempVec = new double[vector.Length+1];
vector.CopyTo(tempVec,0);
tempVec[vector.Length] = num;
vector = tempVec;
}
//————————————————-

public static void AddCell3(ref double[] vector,int num)
{
double[] tempVec = new double[vector.Length+1];
for (int i = 0; i < vector.Length ; i++) {
tempVec[i] = vector[i];
}
tempVec[vector.Length] = num;
vector = tempVec;
}
//————————————————-

public static void Main(string[] args)
{
Console.WriteLine(“Hello World!”);

double[] arr1 = new double[]{};
double[] arr2 = new double[]{};
double[] arr3 = new double[]{};

Stopwatch s1 = Stopwatch.StartNew();
for (int i = 0; i < 100000; i++)
s1.Stop();

Stopwatch s2 = Stopwatch.StartNew();
for (int i = 0; i < 100000; i++)
s2.Stop();

Stopwatch s3 = Stopwatch.StartNew();
for (int i = 0; i < 100000; i++)
s3.Stop();

// TODO: Implement Functionality Here
Console.WriteLine(“{0},{1},{2}”,
s1.ElapsedMilliseconds,
s2.ElapsedMilliseconds,
s3.ElapsedMilliseconds);
Console.Write(“Press any key to continue . . . “);