You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TrustPilotChallenge/dotnet/WhiteRabbit/PrecomputedPermutationsGene...

37 lines
1.1 KiB

7 years ago
namespace WhiteRabbit
{
using System.Collections.Generic;
using System.Linq;
internal static class PrecomputedPermutationsGenerator
7 years ago
{
7 years ago
private static PermutationsGenerator.Permutation[][] Permutations { get; } = new[]
{
GeneratePermutations(0),
GeneratePermutations(1),
GeneratePermutations(2),
GeneratePermutations(3),
GeneratePermutations(4),
GeneratePermutations(5),
GeneratePermutations(6),
GeneratePermutations(7),
7 years ago
};
7 years ago
public static PermutationsGenerator.Permutation[] HamiltonianPermutations(int n)
7 years ago
{
return Permutations[n];
}
private static PermutationsGenerator.Permutation[] GeneratePermutations(int n)
{
var result = PermutationsGenerator.HamiltonianPermutations(n).ToArray();
if (result.Length % Constants.PhrasesPerSet == 0)
7 years ago
{
return result;
7 years ago
}
7 years ago
return result.Concat(Enumerable.Repeat(result[0], Constants.PhrasesPerSet - (result.Length % Constants.PhrasesPerSet))).ToArray();
7 years ago
}
}
}