Пример #1
0
        internal void Run()
        {
            var solutions     = new List <string>();
            int boardSize     = 5;
            var rowPlacements = new int[] { 1, 2, 19, 4, 21, 22, 7, 8, 25, 26, 11, 28, 13, 14, 31, 16 };
            //var rowPlacements = new int[] { 8,1, 2, 11, 4, 13, 14, 7};
            //var rowPlacements = new int[] { 1, 2, 4, 7};
            var pawnPlacements = rowPlacements.Select(encoded => new pawnPlacement()
            {
                placement      = encoded,
                bitMap         = getBitmap(encoded, boardSize),
                representation = writeOut(getBitmap(encoded, boardSize))
            }).ToDictionary(pp => pp.placement, pp => pp);
            var cmb = new Combinatorics();

            cmb.GenerateAllTuples(rowPlacements, boardSize, partialSol => {
                if (columnCheck(partialSol, boardSize, pawnPlacements))
                {
                    var board = string.Join("\n", partialSol.Select(row => pawnPlacements[row].representation));
                    solutions.Add(board);
                    Console.WriteLine(board);
                }
            }, (x, y, z) => true);

            return;
        }
Пример #2
0
        internal void Run()
        {
            var alphabet = new char[] { 'A', 'B' };
            var cmb      = new Combinatorics();

            for (int i = 3; i < 32; i++)
            {
                var win       = 0;
                var lose      = 0;
                var undecided = 0;
                cmb.GenerateAllTuples(alphabet, i, prt => {
                    var str       = new string(prt);
                    var firstABA  = str.IndexOf("ABA");
                    var firstBABA = str.IndexOf("BABA");
                    if (firstABA < 0 && firstBABA < 0)
                    {
                        undecided++;
                    }
                    else
                    {
                        if (firstABA >= 0 && (firstBABA < 0 || firstABA < firstBABA))
                        {
                            win++;
                        }
                        else
                        {
                            lose++;
                        }
                    }

                    return;
                }, (x, y, z) => true);
                Console.WriteLine("W:{0} L:{1} U:{2} T:{3}", win, lose, undecided, win + lose + undecided);
            }
        }
Пример #3
0
        internal void Run()
        {
            var alphabet       = new char[] { 'A', 'B' };
            var cmb            = new Combinatorics();
            int neverLostCount = 0;

            cmb.GenerateAllTuples(alphabet, 14, registerScore, (canddidate, count, partialSolution) => true);
            foreach (var score in scores)
            {
                var neverLost = testLoss(score);
                if (neverLost)
                {
                    neverLostCount++;
                }
                Console.WriteLine("{0}:{1}", new string(score), neverLost?"GOOD":"BAD");
            }
            return;
        }
Пример #4
0
        internal void Run()
        {
            int counter     = 0;
            var c           = new Combinatorics();
            int letterCount = 7;
            var letters     = Enumerable.Range(0, letterCount).Select(offset => (char)(AChar + offset)).ToArray();

            var envelopments = new List <string>();

            c.GenerateAllTuples(letters, 3, tuple =>
            {
                var x = new string(tuple);
                envelopments.Add(x);
            }, checkWrongEnvelope);
            //Console.WriteLine(String.Join("\r\n", envelopments));
            c.GeneratePermutations(envelopments.ToArray(), letterCount, tuple =>
            {
                var y = string.Join(",", tuple);
                //Console.WriteLine(y);
                counter++;
                Debug.Assert(counter <= 3437316);
            }, checkEnvelopePosition);
            Console.WriteLine(counter);
        }