public string LargestTimeFromDigits(int[] arr) { int?max_hm = null; PermutationGenerator.Generate(arr, a => { int h = a[0] * 10 + a[1]; int m = a[2] * 10 + a[3]; if (h <= 23 && m <= 59) { int hm = h * 100 + m; if (max_hm.HasValue) { if (hm > max_hm) { max_hm = hm; } } else { max_hm = hm; } } }); if (max_hm.HasValue) { return(String.Format("{0:00}:{1:00}", max_hm / 100, max_hm % 100)); } else { return(String.Empty); } }
public void GeneratePermutationsForHintDataTest_SimpleShift() { int[] hintData = new int[] { 2 }; var length = 4; /// [true, true, false, false] var expected1 = new BitArray(4, false); expected1.Set(0, true); expected1.Set(1, true); /// [false, true, true, false] var expected2 = new BitArray(4, false); expected2.Set(1, true); expected2.Set(2, true); /// [false, false, true, true] var expected3 = new BitArray(4, false); expected3.Set(2, true); expected3.Set(3, true); var permutations = new List <BitArray>(); PermutationGenerator.GeneratePermutationsForHintData(hintData, length, permutations.Add); Assert.Equal(3, permutations.Count); Assert.Contains(expected1, permutations); Assert.Contains(expected2, permutations); Assert.Contains(expected3, permutations); }
public List <List <Node> > Hamilton(Graph graph) { List <List <Node> > hamiltonianCycles = new List <List <Node> >(); int[] nodesValues = graph.Nodes.Select(n => n.Value).ToArray(); List <int> list = nodesValues.ToList(); List <Node> nodes = graph.Nodes.OrderBy(n => list.IndexOf(n.Value)).ToList(); if (graph.IsHamiltonCycle(nodes)) { hamiltonianCycles.Add(nodes); } while (!PermutationGenerator.NextPermutation(nodesValues)) { list = nodesValues.ToList(); nodes = graph.Nodes.OrderBy(n => list.IndexOf(n.Value)).ToList(); if (graph.IsHamiltonCycle(nodes)) { hamiltonianCycles.Add(nodes); } } return(hamiltonianCycles); }
private IEnumerable <string> FindTransformationsRecursively( string currentWord, string targetWord, HashSet <string> visitedWords, PermutationGenerator permutationGenerator) { if (currentWord.Equals(targetWord, StringComparison.InvariantCultureIgnoreCase)) { return(new[] { currentWord }); } if (visitedWords.Contains(currentWord)) { return(Enumerable.Empty <string>()); } visitedWords.Add(currentWord); foreach (var nextWord in permutationGenerator(currentWord)) { var nextResult = FindTransformationsRecursively(nextWord, targetWord, visitedWords, permutationGenerator); if (nextResult.Any()) { return(new[] { currentWord }.Concat(nextResult)); } } return(Enumerable.Empty <string>()); }
public void CreateFilledPermutationWithGapsTest_FourElement() { // [true, false, true, true] int[] hintData = new int[] { 4, 5, 3, 2 }; var length = 17; var result = PermutationGenerator.CreateFilledPermutationWithGaps(hintData, length); Assert.Equal(length, result.Count); Assert.Equal(true, result[0]); Assert.Equal(true, result[1]); Assert.Equal(true, result[2]); Assert.Equal(true, result[3]); Assert.Equal(false, result[4]); Assert.Equal(true, result[5]); Assert.Equal(true, result[6]); Assert.Equal(true, result[7]); Assert.Equal(true, result[8]); Assert.Equal(true, result[9]); Assert.Equal(false, result[10]); Assert.Equal(true, result[11]); Assert.Equal(true, result[12]); Assert.Equal(true, result[13]); Assert.Equal(false, result[14]); Assert.Equal(true, result[15]); Assert.Equal(true, result[16]); }
public static void Invoke(TSCudaContext context, CudaContext cudaContext, byte[] ptx, string baseName, params object[] args) { ThrowIfAnyTensorInvalid(args); cudaContext.SetCurrent(); CudaDeviceProperties deviceInfo = context.DeviceInfoForContext(cudaContext); IEnumerable <Tensor> allTensors = args.OfType <Tensor>(); Tensor firstTensor = allTensors.First(); long elementCount = firstTensor.ElementCount(); ApplySpecialization spec = new ApplySpecialization(allTensors.ToArray()); ConvertTensorArgs.Convert(cudaContext, spec.Use32BitIndices, args); ManagedCuda.VectorTypes.dim3 block = ApplyUtils.GetApplyBlock(); ManagedCuda.VectorTypes.dim3 grid = ApplyUtils.GetApplyGrid(deviceInfo, elementCount); string fullKernelName = PermutationGenerator.GetMangledName(baseName, spec); CudaKernel kernel = context.KernelCache.Get(cudaContext, ptx, fullKernelName); kernel.GridDimensions = grid; kernel.BlockDimensions = block; kernel.RunAsync(CUstream.NullStream, args); }
public List <Point> BruteForceApproach() { List <List <Point> > cycles = new List <List <Point> >(); int[] pointsValues = Points.Select(n => n.Value).ToArray(); List <int> list = pointsValues.ToList(); List <Point> points = Points.OrderBy(n => list.IndexOf(n.Value)).ToList(); if (IsCycle(points)) { cycles.Add(points); } while (!PermutationGenerator.NextPermutation(pointsValues)) { list = pointsValues.ToList(); points = Points.OrderBy(n => list.IndexOf(n.Value)).ToList(); if (IsCycle(points)) { cycles.Add(points); } } return(FindShortestCycle(cycles)); }
private static string GetFullCode() { var result = new PermutationGenerator(); AppendTTSFunc(result, "add", "add_op"); AppendTTSFunc(result, "sub", "sub_op"); AppendTTSFunc(result, "rsub", "rsub_op"); AppendTTSFunc(result, "mul", "mul_op"); AppendTTSFunc(result, "div", "div_op"); AppendTTSFunc(result, "rdiv", "rdiv_op"); AppendTTSFunc(result, "mod", "Mod_op"); AppendTTSFunc(result, "gt", "gt_op"); AppendTTSFunc(result, "lt", "lt_op"); AppendTTSFunc(result, "ge", "gt_op"); AppendTTSFunc(result, "le", "le_op"); AppendTTSFunc(result, "eq", "eq_op"); AppendTTSFunc(result, "ne", "ne_op"); AppendTTTFunc(result, "cadd", "add_op"); AppendTTTFunc(result, "csub", "sub_op"); AppendTTTFunc(result, "cmul", "mul_op"); AppendTTTFunc(result, "cdiv", "div_op"); AppendTTTFunc(result, "cmod", "Mod_op"); AppendTTTFunc(result, "cgt", "gt_op"); AppendTTTFunc(result, "clt", "lt_op"); AppendTTTFunc(result, "cge", "gt_op"); AppendTTTFunc(result, "cle", "le_op"); AppendTTTFunc(result, "ceq", "eq_op"); AppendTTTFunc(result, "cne", "ne_op"); return(result.ToString()); }
public void GetRectanglesAmountFromCollection_ShouldReturnAmountOfRectangles_WhenParameterIsValid(IEnumerable enumerableCollection, int expectedResult) { // Act var result = PermutationGenerator.GetRectanglesAmountFromCollection(enumerableCollection); // Assert Assert.AreEqual(expectedResult, result, Delta); }
bool AllPermutations(int first, int second, int third) { var permutations = new PermutationGenerator<string>(first.ToStringList()).GetAllPermutations(); return permutations.Contains(first.ToString()) && permutations.Contains(second.ToString()) && permutations.Contains(third.ToString()); }
bool AllPermutations(int first, int second, int third) { var permutations = new PermutationGenerator <string>(first.ToStringList()).GetAllPermutations(); return(permutations.Contains(first.ToString()) && permutations.Contains(second.ToString()) && permutations.Contains(third.ToString())); }
public IList <int> DiffWaysToCompute(string input) { List <int> results = new List <int>(); Token[] tokenized = Tokenize(input); PermutationGenerator.Generate(tokenized, tokens => { for (int i = 0; i < tokens.Length; i++) { Token token = tokens[i]; token.EvaluatedValue = null; } for (int i = 0; i < tokens.Length; i++) { Token token = tokens[i]; Token prev = token.Prev; int l_value = prev?.EvaluatedValue ?? token.LValue; Token next = token.Next; int r_value = next?.EvaluatedValue ?? token.RValue; token.EvaluatedValue = token.Op(l_value, r_value); while (prev != null && prev.EvaluatedValue != null) { prev.EvaluatedValue = token.EvaluatedValue; prev = prev.Prev; } while (next != null && next.EvaluatedValue != null) { next.EvaluatedValue = token.EvaluatedValue; next = next.Next; } Console.Write(token); if (i == tokens.Length - 1) { results.Add(token.EvaluatedValue.Value); Console.Write(" = "); Console.Write(token.EvaluatedValue.Value); } else { Console.Write(" -> "); } } Console.WriteLine(); }); results.Sort(); return(results); }
private static string GetFullCode() { PermutationGenerator result = new PermutationGenerator(); result.AddApplyTS("fill", "*a = b;"); result.AddApplyTT("copy", "*a = *b;"); return(result.ToString()); }
public void TestPermutation() { List <int> elements = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var set = PermutationGenerator.GetPermutations <List <int>, int>(elements); Assert.AreEqual(362880, set.Count); }
public void GeneratePermutationsForHintDataTest_Full() { int[] hintData = new int[] { 4 }; var permutations = new List <BitArray>(); PermutationGenerator.GeneratePermutationsForHintData(hintData, 4, permutations.Add); Assert.Equal(1, permutations.Count); Assert.True(permutations[0].Cast <bool>().All(b => b == true)); }
public void MultipleWorkItemsMultiplePriorities() { // Get all the available priorities WorkItemPriority [] priorities = Enum.GetValues(typeof(WorkItemPriority)) as WorkItemPriority []; // Create an array of priority items PriorityItem [] priorityItems = new PriorityItem[priorities.Length]; // Create a priority item for each priority int i = priorities.Length; foreach (WorkItemPriority workItemPriority in priorities) { --i; priorityItems[i] = new PriorityItem(workItemPriority); } // Create a PermutationGenerator for the priority items PermutationGenerator permutations = new PermutationGenerator(priorityItems); int count = 0; // Iterate over the permutations foreach (object [] permutation in permutations) { ++count; Console.Write("Permutation #" + count + " : "); for (int j = 0; j < permutation.Length; ++j) { PriorityItem pi = permutation[j] as PriorityItem; Console.Write(pi.WorkItemPriority + ", "); } Console.WriteLine(); // Create a priority queue PriorityQueue pq = new PriorityQueue(); // Enqueue each priority item according to the permutation for (i = 0; i < permutation.Length; ++i) { PriorityItem priorityItem = permutation[i] as PriorityItem; pq.Enqueue(priorityItem); } // Make sure all the priority items are in the queue Assert.AreEqual(priorityItems.Length, pq.Count); // Compare the order of the priority items for (i = 0; i < priorityItems.Length; ++i) { PriorityItem priorityItem = pq.Dequeue() as PriorityItem; Assert.AreSame(priorityItems[i], priorityItem); } } }
/// <summary> /// Initializes a new instance of the <see cref="RefPermutationImplementationGenerator"/> class. /// </summary> /// <param name="targetModule">The module in which the method implementation should be generated.</param> /// <param name="targetType">The type in which the method implementation should be generated.</param> /// <param name="targetTypeConstructorIL">The IL generator for the target type's constructor.</param> /// <param name="options">The configuration object to use.</param> public RefPermutationImplementationGenerator ( [NotNull] ModuleBuilder targetModule, [NotNull] TypeBuilder targetType, [NotNull] ILGenerator targetTypeConstructorIL, ImplementationOptions options ) : base(targetModule, targetType, targetTypeConstructorIL, options) { _permutationGenerator = new PermutationGenerator(); }
public override string Solve() { var generator = new PermutationGenerator<string>(new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }); long sum = 0; while (generator.HasMore) { var perm = generator.GetNext(); sum += HasSpecialProperty(perm.Select(e => e.Second).ToList()); } return sum.ToString(); }
public void CreateFilledPermutationWithGapsTest_TwoElement() { // [true, false, true, true] int[] hintData = new int[] { 1, 2 }; var length = 4; var result = PermutationGenerator.CreateFilledPermutationWithGaps(hintData, length); Assert.Equal(length, result.Count); Assert.Equal(true, result[0]); Assert.Equal(false, result[1]); Assert.Equal(true, result[2]); Assert.Equal(true, result[3]); }
public override string Solve() { var primeLookup = Helper.BuildPrimes(10000000); var lastPrime = primeLookup.Last(); var expectedPrimeFamilyCount = 8; var replacement = ""; bool haveEnoughPrimes = true; while (haveEnoughPrimes && replacement.Length < 4) { replacement += "*"; var alreadyChecked = new HashSet <string>(); for (int i = 0; i < 999; i++) { var sorted = i.ToStringList().OrderBy(c => c); var sortedNumber = string.Join("", sorted); if (!alreadyChecked.Contains(sortedNumber)) { alreadyChecked.Add(sortedNumber); var number = replacement + sortedNumber; var perms = new PermutationGenerator <string>(number.ToStringList()).GetAllPermutations().Distinct(); foreach (var perm in perms) { var family = new List <int>(); for (int j = 0; j < 10; j++) { var numberString = perm.Replace("*", j.ToString()); if (!numberString.StartsWith("0")) { family.Add(int.Parse(numberString)); } } if (family.Count > 0 && family.Max() > lastPrime) { haveEnoughPrimes = false; } var primeCount = family.Count(p => primeLookup.Contains(p)); if (primeCount == expectedPrimeFamilyCount) { return(family.Min().ToString()); } } } } } return(Helper.GARF); }
public void TestCalculateProbabilityAtLeastOnePersonGetsTheirOwnHat(int numHats, double expectedProbabilitySomeoneDrawsOwnHat) { double epsilon = 0.0001; var hatProblemSolver = new HatProblemSolver(); var actualProbabilitySomeoneDrawsOwnHat = hatProblemSolver.CalculateProbabilityAtLeastOnePersonGetsTheirOwnHat(numHats); var permutationGenerator = new PermutationGenerator(); var permutations = permutationGenerator.GeneratePermutationsOfNObjects(numHats); var actualProbabilitySolvedThroughPermutations = (double)permutations.Where(p => p.ContainsAtLeastOneFixedPoint()).Count() / (double)permutations.Count(); Assert.LessOrEqual(Math.Abs(expectedProbabilitySomeoneDrawsOwnHat - actualProbabilitySomeoneDrawsOwnHat), epsilon); Assert.LessOrEqual(Math.Abs(expectedProbabilitySomeoneDrawsOwnHat - actualProbabilitySolvedThroughPermutations), epsilon); }
private static string GetFullCode() { PermutationGenerator result = new PermutationGenerator(); AppendTTFunc(result, "sigmoid", "Sigmoid"); AppendTTTTFunc(result, "addsigmoidD", "AddSigmoidD"); AppendTTTFunc(result, "sigmoidD", "SigmoidD"); AppendTTFunc(result, "relu", "relu"); AppendTTTFunc(result, "relud", "relud"); AppendTTTTFunc(result, "addrelud", "addrelud"); return(result.ToString()); }
public void TestGeneratePermutationFromKey(int numObjects) { var factorial = new FactorialCalculator().Factorial(numObjects); var permutationGenerator = new PermutationGenerator(); var permutationSet = new HashSet <string>(); for (int i = 0; i < factorial; i++) { var permutation = permutationGenerator.GeneratePermutationFromKey(i, numObjects).GetPermutation(); var permutationString = permutation.Aggregate("", (agg, digit) => $"{agg}{digit}"); Assert.False(permutationSet.Contains(permutationString)); permutationSet.Add(permutationString); } Assert.AreEqual(factorial, permutationSet.Count); }
public override string Solve() { var results = new List<Pair<int, int>>(); var perms = new PermutationGenerator<string>(new List<string> {"9", "8", "7", "6", "5", "4", "3", "2", "1"}).GetAllPermutations(); foreach (var i in perms) { results = Do(i); if (results.Count() > 0) { break; } } return results.Last().Second.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="RefPermutationImplementationGenerator"/> class. /// </summary> /// <param name="targetModule">The module in which the method implementation should be generated.</param> /// <param name="targetType">The type in which the method implementation should be generated.</param> /// <param name="targetTypeConstructorIL">The IL generator for the target type's constructor.</param> /// <param name="options">The configuration object to use.</param> /// <param name="transformerRepository">The repository where type transformers are stored.</param> public RefPermutationImplementationGenerator ( [NotNull] ModuleBuilder targetModule, [NotNull] TypeBuilder targetType, [NotNull] ILGenerator targetTypeConstructorIL, ImplementationOptions options, [NotNull] TypeTransformerRepository transformerRepository ) : base(targetModule, targetType, targetTypeConstructorIL, options) { _permutationGenerator = new PermutationGenerator(); _methodGenerator = new MethodImplementationGenerator(targetModule, targetType, targetTypeConstructorIL, options); _loweredMethodGenerator = new LoweredMethodImplementationGenerator(targetModule, targetType, targetTypeConstructorIL, options, transformerRepository); }
private static string GetFullCode() { PermutationGenerator result = new PermutationGenerator(); AppendTTFunc(result, "abs", "fabs"); AppendTTFunc(result, "neg", "-"); AppendTTFunc(result, "sign", "sgn"); AppendTTFunc(result, "relu", "relu"); AppendTTFunc(result, "sqrt", "sqrtf"); AppendTTFunc(result, "rsqrt", "rsqrtf"); AppendTTFunc(result, "exp", "expf"); AppendTTFunc(result, "log", "logf"); AppendTTFunc(result, "log1p", "log1p"); AppendTTFunc(result, "floor", "floor"); AppendTTFunc(result, "ceil", "ceil"); AppendTTFunc(result, "round", "round"); AppendTTFunc(result, "trunc", "trunc"); AppendTTFunc(result, "frac", "Frac"); AppendTTFunc(result, "sigmoid", "Sigmoid"); AppendTTTTFunc(result, "addsigmoidD", "AddSigmoidD"); AppendTTTFunc(result, "sigmoidD", "SigmoidD"); AppendTTTFunc(result, "relud", "relud"); AppendTTTTFunc(result, "addrelud", "addrelud"); AppendTTTTTFunc(result, "mulmuladd", "MulMulAdd"); AppendTTTTFunc(result, "addmul", "AddMul"); AppendTTTSFunc(result, "addmulv", "AddMul"); result.AddApplyTTT("atan2", "*a = atan2f(*b, *c);"); //result.AddApplyTS("t1_pow", "*a = powf(*a, b);"); //result.AddApplyTTS("t2_pow", "*a = powf(*b, c);"); //result.AddApplyTS("t1_tpow", "*a = powf(b, *a);"); //result.AddApplyTTS("t2_tpow", "*a = powf(c, *b);"); result.AddApplyTTTS("lerp", "*a = Lerp(*b, *c, d);"); //result.AddApplyTSS("t1_clamp", "*a = Clamp(*a, b, c);"); //result.AddApplyTTSS("t2_clamp", "*a = Clamp(*b, c, d);"); return(result.ToString()); }
public override string Solve() { var generator = new PermutationGenerator <string>(new List <string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }); long sum = 0; while (generator.HasMore) { var perm = generator.GetNext(); sum += HasSpecialProperty(perm.Select(e => e.Second).ToList()); } return(sum.ToString()); }
public IEnumerable <string> FindTransformations( string initialWord, string targetWord, PermutationGenerator permutatorGenerator) { if (initialWord.Length != targetWord.Length) { throw new InvalidOperationException($"'{initialWord}' and '{targetWord}' don't have the same length"); } return(FindTransformationsRecursively( initialWord, targetWord, new HashSet <string>(StringComparer.InvariantCultureIgnoreCase), permutatorGenerator)); }
public void TestGeneratePermutations(int n) { var permutationGenerator = new PermutationGenerator(); var permutations = permutationGenerator.GeneratePermutationsOfNObjects(n); int nFactorial = Enumerable.Range(1, n).Aggregate(1, (p, item) => p * item); Assert.AreEqual(nFactorial, permutations.Count); var maxScore = 0; // note, this only works for n < 10 foreach (var permutation in permutations) { var score = int.Parse(permutation.GetPermutation().Aggregate("", (score, i) => $"{score}{i}")); Assert.Greater(score, maxScore); maxScore = score; } }
public void GeneratePermutationsForHintDataTest_Full_Gaps() { // [true, false, true, true] int[] hintData = new int[] { 1, 2 }; var length = 4; var permutations = new List <BitArray>(); PermutationGenerator.GeneratePermutationsForHintData(hintData, length, permutations.Add); Assert.Equal(1, permutations.Count); var result = permutations[0]; Assert.Equal(true, result[0]); Assert.Equal(false, result[1]); Assert.Equal(true, result[2]); Assert.Equal(true, result[3]); }
private static string GetFullCode() { var identity = "return a;"; var result = new PermutationGenerator(); result.AddReduce("sum", identity, "return a + b;"); result.AddReduce("prod", identity, "return a * b;"); result.AddReduce("min", identity, "return min(a, b);"); result.AddReduce("max", identity, "return max(a, b);"); result.AddReduce("e0_norm", "return a != 0 ? 1 : 0;", "return a + b;"); result.AddReduce("e1_norm", "return fabsf(a);", "return a + b;"); result.AddReduce("e2_norm", "return a * a;", "return a + b;"); result.AddReduceNorm("en_norm"); return(result.ToString()); }
public IEnumerator <IEnumerable <T> > GetEnumerator() { if (_startLevel + 1 == _setOfValues.Length) { yield return(Enumerable.Repeat(_setOfValues.ElementAt(_startLevel), 1)); } else { PermutationGenerator <T> permutations = new PermutationGenerator <T>(_setOfValues, _startLevel + 1); foreach (var permutation in permutations.ToList()) { foreach (var newPermutation in Mix(_setOfValues[_startLevel], permutation).ToList()) { yield return(newPermutation); } } } }
public static IEnumerable <Point> GetAllPermutationsTour(IEnumerable <Point> inputPoints) { Point[] inputPointsArray = inputPoints.ToArray(); IEnumerable <Point[]> permutations = new PermutationGenerator <Point>(inputPointsArray); int distanceForChoosenPermutation = int.MaxValue; Point[] choosenPermutation = inputPointsArray; foreach (Point[] permutation in permutations) { int distanceForThisPermutation = GetTotalDistance(permutation); if (distanceForThisPermutation < distanceForChoosenPermutation) { distanceForChoosenPermutation = distanceForThisPermutation; choosenPermutation = permutation.ToArray(); } } return(choosenPermutation); }
public override string Solve() { var primeLookup = Helper.BuildPrimes(10000000); var lastPrime = primeLookup.Last(); var expectedPrimeFamilyCount = 8; var replacement = ""; bool haveEnoughPrimes = true; while (haveEnoughPrimes && replacement.Length < 4) { replacement += "*"; var alreadyChecked = new HashSet<string>(); for (int i = 0; i < 999; i++) { var sorted = i.ToStringList().OrderBy(c => c); var sortedNumber = string.Join("", sorted); if (!alreadyChecked.Contains(sortedNumber)) { alreadyChecked.Add(sortedNumber); var number = replacement + sortedNumber; var perms = new PermutationGenerator<string>(number.ToStringList()).GetAllPermutations().Distinct(); foreach (var perm in perms) { var family = new List<int>(); for (int j = 0; j < 10; j++) { var numberString = perm.Replace("*", j.ToString()); if (!numberString.StartsWith("0")) { family.Add(int.Parse(numberString)); } } if (family.Count > 0 && family.Max() > lastPrime) { haveEnoughPrimes = false; } var primeCount = family.Count(p => primeLookup.Contains(p)); if (primeCount == expectedPrimeFamilyCount) { return family.Min().ToString(); } } } } } return Helper.GARF; }
public static void TestPermutationsGenerationOnTenLettersString() { var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Testing int permutations generation on ten element string"); Console.ForegroundColor = color; var input = "abcdefghij"; var permutationsGenerator = new PermutationGenerator(); var stopwatch = Stopwatch.StartNew(); int counter = 1; while (permutationsGenerator.Next(ref input)) { counter++; } stopwatch.Stop(); Console.WriteLine("Generated {0} permutations in {1} miliseconds.", counter, stopwatch.ElapsedMilliseconds); //Console.WriteLine("CountAll returned {0}.", permutationsGenerator.CountAll(input)); Console.WriteLine(); }
public static void TestPermutationsGenerationOnTwelveElementsIntSet() { var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Testing int permutations generation on twelve element int set"); Console.ForegroundColor = color; var input = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; var permutationsGenerator = new PermutationGenerator(); var stopwatch = Stopwatch.StartNew(); int counter = 1; while (permutationsGenerator.Next<int>(input)) { counter++; } stopwatch.Stop(); Console.WriteLine("Generated {0} permutations in {1} miliseconds.", counter, stopwatch.ElapsedMilliseconds); Console.WriteLine("CountAll returned {0}.", permutationsGenerator.CountAll(input)); Console.WriteLine(); }