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...

36 lines
1.1 KiB

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