Example #1
0
        public static bool Solve()
        {
            Console.WriteLine("Calculating possible permutations...");

            sData.GetPermutations();

            Console.WriteLine("Permutations calculated.");
            Console.WriteLine("------------------------------");



            emptyStartCount = sData.CountEmptys();

            int removeCount = 0;

            for (int o = 0; o < 5; o++)
            {
                removeCount = 0;
                for (int i = 0; i < 81; i++)
                {
                    removeCount += sData.CheckISValid(i);
                }
                Console.WriteLine($"Removed ({removeCount}) this run");
                if (removeCount == 0)
                {
                    Console.WriteLine($"No more removed items found.");
                    break;
                }
            }

            for (int i = 0; i < 81; i++)
            {
                Console.WriteLine($"==============================================");
                List <FlattenValue> result = sData.Flat(i);
                int[] indexOfI             = i.getIndexOf(Dimension.Line);
                Console.WriteLine($"Index [{i}] [{indexOfI[0]}][{indexOfI[1]}] == result count: {result.Count}");
                int    totaalCount = result.Sum(x => x.count);
                double percentage  = 0;
                for (int u = 0; u < result.Count; u++)
                {
                    percentage  = (double)result[u].count / (double)totaalCount;
                    percentage *= 100;
                    Console.WriteLine($"== ({result[u].value}) Count: {result[u].count} == {percentage.ToString("0.0")} %");
                }
                Console.WriteLine($"==============================================");

                sData.Fill(i, result);
            }

            int empty = sData.CountEmptys();

            Console.WriteLine($"Starting empty count: {emptyStartCount}, new empty count: {empty}, filled totaal: {emptyStartCount - empty}");


            int totaalPosLeft     = 0;
            int linetotaalPosLeft = 0;

            for (int y = 0; y < 9; y++)
            {
                linetotaalPosLeft = 0;
                for (int x = 0; x < 9; x++)
                {
                    Console.Write(sData.sdLines[y].data[x] + ",");
                    linetotaalPosLeft += sData.sdLines[y].possiblePermutations.Count();
                    linetotaalPosLeft += sData.sdCols[y].possiblePermutations.Count();
                    linetotaalPosLeft += sData.sdBlocks[y].possiblePermutations.Count();
                }
                Console.WriteLine($" == {linetotaalPosLeft} options left");
                totaalPosLeft += linetotaalPosLeft;
            }

            Console.WriteLine($"Totaal opions left: {totaalPosLeft/243}");

            if (empty > 0)
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        public static void Call()
        {
            input = Hardest;
            if (sData == null)
            {
                sData = new SDataSet();
            }
            sData.Reset();
            Random r = new Random();

            Console.WriteLine("resetting solver...");

            sData.Permutations = SolverHelper.Permute(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            if (showDebug)
            {
                Console.WriteLine($"Possible line solutions: {sData.Permutations.Count}");
            }
            if (showDebug)
            {
                Console.WriteLine($"Possible line length: {sData.Permutations[0].Count}");
            }
            if (showDebug)
            {
                Console.WriteLine($"Check count at {1}: {sData.Permutations.Where(x => x[0] == 1).Count()}");
            }

            Console.WriteLine("Reading sudoku input...");
            sData.ReadSudokuData(input, Dimension.Line);
            sData.ReadSudokuData(input, Dimension.Colum);
            sData.ReadSudokuData(input, Dimension.Block);

            if (showDebug)
            {
                Console.WriteLine("Converted to Sudoku data set model.");
            }
            if (showDebug)
            {
                Console.WriteLine("------------------------------");
            }
            if (showDebug)
            {
                Console.WriteLine("Calculating possible permutations...");
            }

            sData.GetPermutations();

            if (showDebug)
            {
                Console.WriteLine("Permutations calculated.");
            }
            if (showDebug)
            {
                Console.WriteLine("------------------------------");
            }


            int[] li;
            int[] ci;
            int[] bi;



            for (int o = 0; o < 10; o++)
            {
                for (int i = 0; i < 81; i++)
                {
                    sData.CheckISValid(i);
                }
            }



            for (int i = 0; i < 9; i++)
            {
                Console.WriteLine($"==============================================");
                Console.WriteLine($"Y: {i} ==" +
                                  $" li: {sData.sdLines[i].possiblePermutations.Count()}," +
                                  $" ci: {sData.sdCols[i].possiblePermutations.Count()}," +
                                  $" bi: {sData.sdBlocks[i].possiblePermutations.Count()}");

                for (int u = 1; u < 10; u++)
                {
                    Console.WriteLine($"Checking {u}, Count: {sData.sdBlocks[i].possiblePermutations.Count(x => x[0] == u)}");
                }
            }



            Console.ReadLine();
        }