C# permutation implementation