Пример #1
0
        public static bool IsPuzzleValid(SudokuPuzzle puzzle)
        {
            int sum(SudokuPiece[,] p)
            {
                int result = 0;

                for (int i = 0; i < 3; ++i)
                {
                    for (int k = 0; k < 3; ++k)
                    {
                        result += p[i, k].Value;
                    }
                }
                return(result);
            }

            for (int i = 0; i < 9; ++i)
            {
                if (puzzle.GetRow(i).Sum(x => x.Value) != 45 || puzzle.GetColumn(i).Sum(x => x.Value) != 45 || sum(puzzle.GetArea(i)) != 45)
                {
                    return(false);
                }
            }

            return(true);
        }