Exemplo n.º 1
0
        internal void Run()
        {
            var ballcount  = 12;
            var targetInfo = (ballcount * (ballcount - 1)) / 2;
            var balls      = Enumerable.Range(0, ballcount).Select(chrOffset => (char)('a' + chrOffset)).ToArray();
            var cmb        = new Combinatorics();
            var picks      = new Dictionary <string, char[]>();

            cmb.GenerateCombinations(balls, 4, result =>
            {
                var str    = new string(result);
                picks[str] = result.Take(4).ToArray();
            }, (candidate, count, partialResult) => true);
            var knownInfo = new HashSet <weigh>();
            var counter   = 1;

            while (knownInfo.Count < targetInfo)
            {
                var weighInfos = picks.ToDictionary(kvp => kvp.Key, kvp => getRevealedInfo(kvp.Value, knownInfo));
                var bestWeigh  = picks[weighInfos.OrderByDescending(kvp => kvp.Value).FirstOrDefault().Key];
                markBestWeigh(bestWeigh, knownInfo);
                Console.WriteLine("{0}-{1}", counter, new string(bestWeigh));
                counter++;
            }
            return;
        }
Exemplo n.º 2
0
        internal void Run()
        {
            var boardSize = 4;
            var squares   = Enumerable.Range(0, boardSize * boardSize).Select(ordinal => getCoord(ordinal, boardSize)).ToArray();
            var cmb       = new Combinatorics();
            var solutions = new List <coord[]>();

            cmb.GenerateCombinations(squares, 8, result => solutions.Add(result.ToArray()), (candidate, countSoFar, partialSolution) => checkCandidate(candidate, partialSolution.Take(countSoFar).ToArray()));
            foreach (var solution in solutions)
            {
                printSolution(solution, boardSize);
                Console.WriteLine("----");
            }
            return;
        }
Exemplo n.º 3
0
 internal void Run()
 {
     List<int[]> combos = new List<int[]>();
     var cmb = new Combinatorics();
     var numbers = Enumerable.Range(1, 20).ToArray();
     cmb.GenerateCombinations(numbers, 9, combo =>
     {
         if (combo.Sum() == 51)
         {
             combos.Add(combo.ToArray());
         }
     }, (itm, idx, partialCombo) => true);
     foreach (var combo in combos)
     {
         cmb.GeneratePermutations(combo, 9, result =>
          {
              return;
          }
         , (candidate, position, partialSolution) =>
          checkForSquareMagicSquare(candidate, position, partialSolution));
     }
     return;
 }