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);
        }