#C13472. Valid Sudoku Board
Valid Sudoku Board
Valid Sudoku Board
You are given a 9×9 Sudoku board represented as a grid of characters. Each cell is either a digit from 1 to 9 or the character ., representing an empty cell. A Sudoku board is valid if:
- Each row contains the digits 1-9 without repetition (ignoring .).
- Each column contains the digits 1-9 without repetition (ignoring .).
- Each of the 9 sub-boxes of size 3×3 (defined by indices) contains the digits 1-9 without repetition (ignoring .).
In mathematical terms, for each row, column, and 3×3 sub-box, if we denote the set of non-empty entries as \( S \), then the board is valid if \(|S| = |\text{unique}(S)|\).
Your task is to determine whether a given board is valid. Note that the board does not need to be solvable.
inputFormat
The input consists of exactly 9 lines, each line containing 9 tokens separated by spaces. Each token is either a digit ('1'-'9') or a dot ('.') representing an empty cell.
For example:
5 3 . . 7 . . . . 6 . . 1 9 5 . . . . 9 8 . . . . 6 . 8 . . . 6 . . . 3 4 . . 8 . 3 . . 1 7 . . . 2 . . . 6 . 6 . . . . 2 8 . . . . 4 1 9 . . 5 . . . . 8 . . 7 9
outputFormat
Output a single line with either True
or False
(without quotes) indicating whether the Sudoku board is valid.
5 3 . . 7 . . . .
6 . . 1 9 5 . . .
. 9 8 . . . . 6 .
8 . . . 6 . . . 3
4 . . 8 . 3 . . 1
7 . . . 2 . . . 6
. 6 . . . . 2 8 .
. . . 4 1 9 . . 5
. . . . 8 . . 7 9
True