Exemple #1
0
        bool VerifySoduku()
        {
            // All bytes must be 1..9
            if (Sudoku.Any(x => x < 1 || x > 9))
            {
                return(false);
            }


            // Search each row, col and cell for non-uniqvue valze
            for (int i = 0; i < ROW_ELEMENT_COUNT; i++)
            {
                // Generate sequence for row, col and cell
                // Make sure to generate an index that satifies these conditions
                var row  = GetRowIterator(i * 9).ToHashSet();
                var col  = GetColIterator(i).ToHashSet();
                var cell = GetCellIterator((i / 3) * ROW_ELEMENT_COUNT * 3 + i).ToHashSet();

                // There must be 9 distinct values
                if (Toolbox.AllDistinct(row.Select(x => Sudoku[x])) == false)
                {
                    return(false);
                }
                if (Toolbox.AllDistinct(col.Select(x => Sudoku[x])) == false)
                {
                    return(false);
                }
                if (Toolbox.AllDistinct(cell.Select(x => Sudoku[x])) == false)
                {
                    return(false);
                }
            }

            return(true);
        }