using System.Collections.Generic;
public static void Main()
HashSet<string> hash = new HashSet<string>();
foreach (var c in GetPermutations("123".ToCharArray()))
string s = string.Join("", c);
Console.WriteLine("EEEEEEEE");
public static IEnumerable<IReadOnlyList<T>> GetPermutations<T>(IReadOnlyList<T> input)
long subSwaps = input.Count*2;
int subSwapIndexMax = input.Count - 2;
for (long index = 0; index < input.Count; index++)
T[] permutation = input.ToArray();
MoveToFront(index, permutation);
yield return permutation;
int pos = subSwapIndexMax;
for (int s = 0; s < subSwaps; s++)
Swap(ref permutation[pos], ref permutation[pos + 1]);
if (pos == subSwapIndexMax)
yield return permutation;
public static long Factorial(int i) => i == 1 ? 1 : i * Factorial(i - 1);
public static void Swap<T>(ref T a, ref T b)
public static void MoveToFront<T>(long index, T[] array)
for (long k = index; k > 0; k--)