Esempio n. 1
0
 static bool AddPermutation <T>(T[] items, PermutationKey n, int[] p, int oldi, Func <T[], bool> process)
 {
     if (p.Length == n.NumItemsInPermutation)
     {
         return(process(p.Select(i => items[i]).ToArray()));
     }
     else
     {
         int  lowerLimit = n.CombinationsOnly ? oldi : 0;
         bool cont       = true;
         for (int i = lowerLimit; i < n.NumItemsTotal && cont; i++)
         {
             if (n.AllowDuplicates || !p.Contains(i))
             {
                 cont = AddPermutation(items, n, p.Concat(new[] { i }).ToArray(), i, process);
             }
         }
     }
     return(true);
 }
Esempio n. 2
0
        public static void Get <T>(T[] items, int numItemsInPermutation, bool allowDuplicates, bool combinationsOnly, Func <T[], bool> process)
        {
            var permutationKey = new PermutationKey(allowDuplicates, combinationsOnly, items.Length, numItemsInPermutation);

            AddPermutation(items, permutationKey, new int[] { }, 0, process);
        }