コード例 #1
0
ファイル: Model.cs プロジェクト: momor666/Countdown-2
        public static SolverResults Solve(int[] tiles, int target)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            SolverResults results = new SolverResults();

            for (int k = 2; k <= tiles.Length; k++)
            {
                Combinations <int> combinations = new Combinations <int>(tiles, k);

                foreach (List <int> combination in combinations)
                {
                    Permutations <int> permutations = new Permutations <int>(combination);

                    Parallel.ForEach(permutations,
                                     // the partitions local solver
                                     () => new SolvingEngine(target, k),
                                     // the parallel action
                                     (permutation, loopState, solvingEngine) =>
                    {
                        solvingEngine.Solve(permutation);
                        return(solvingEngine);
                    },
                                     // local finally
                                     (solvingEngine) => results.AggregateData(solvingEngine));
                }
            }

            stopWatch.Stop();
            results.Elapsed = stopWatch.Elapsed;

            return(results);
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="p"></param>
 public PermutationEnumerator(Permutations <T> p)
 {
     setUpFirstItem = true;
     current        = p.input;
     comparer       = p.comparer;
 }