コード例 #1
0
        public static bool IsMinimal(this Grid grid)
        {
            Contract.Assume(!(grid is null));

            int hintCount = 0;
            var array     = grid.ToArray();
            var valueList = new Queue <(int, int)>();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (array[i, j] != 0)
                    {
                        hintCount++;
                        valueList.Enqueue((i, j));
                    }
                }
            }

            var tempArrays = new int[hintCount][, ];

            for (int i = 0; i < hintCount; i++)
            {
                var(r, c)           = valueList.Dequeue();
                tempArrays[i]       = (int[, ])array.Clone();
                tempArrays[i][r, c] = 0;
            }

            var solver = new DancingLinksSolver();

            return(tempArrays.All(gridArray => solver.Solve(gridArray, out _) is null));
        }
コード例 #2
0
 public static bool IsUnique(this Grid grid, [NotNullWhen(true)] out Grid?resultIfUnique)
 {
     try
     {
         var result = new DancingLinksSolver().Solve(grid, out _);
         resultIfUnique = result;
         return(!(result is null));
     }
     catch
     {
         resultIfUnique = default;
         return(false);
     }
 }