After using Google to find examples, I found the following example goes which works for generating permutations:
namespace ConsoleApp1
{
class Program
{
public static void Main()
{
int n, i;
formPermut test = new formPermut();
int[] arr1 = new int[5];
Console.WriteLine("\n\n Recursion : Generate all possible permutations of an array :");
Console.WriteLine("------------------------------------------------------------------");
Console.Write(" Input the number of elements to store in the array [maximum 5 digits ] :");
n = Convert.ToInt32(Console.ReadLine());
Console.Write(" Input {0} number of elements in the array :\n", n);
for (i = 0; i < n; i++)
{
Console.Write(" element - {0} : ", i);
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("\n The Permutations with a combination of {0} digits are : \n", n);
test.prnPermut(arr1, 0, n - 1);
Console.Write("\n\n");
Console.ReadKey();
}
class formPermut
{
public void swapTwoNumber(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
public void prnPermut(int[] list, int k, int m)
{
int i;
if (k == m)
{
for (i = 0; i <= m; i++)
Console.Write("{0}", list[i]);
Console.Write(" ");
}
else
for (i = k; i <= m; i++)
{
swapTwoNumber(ref list[k], ref list[i]);
prnPermut(list, k + 1, m);
swapTwoNumber(ref list[k], ref list[i]);
}
}
}
}
}
So, if I have 2 input values 1 and 2, the above code will return the following results 12 and 21.
I need it to return more results than that for example:
1 12 2 21
If I type in 3 values 1 and 2 and 3, at the moment it returns:
123 132 213 231 321 312
But I need it to return all the double digit and single digit permutations at the same time.
Anyone know how I can go about doing that?
For example:
1 2 3 12 13 21 23 31 32 123 132 213 321 312 and so on, I may have missed out some combinations/permutations.
My end goal is to be able to do the same thing, but with strings, so if the input is one and two, the output would be:
one onetwo two twoone
for three inputs such as:
one and two and three
the output would be:
one two three onetwo onethree twoone twothree threeone threetwo onetwothree onethreetwo twoonethree threetwoone threeonetwo assuming i have not missed out any combinations.