296. Is the Grid Still Legal
A 9 by 9 grid holds digits 1 to 9 and . for an empty cell. Print yes if
the filled cells break no rule and no otherwise. Empty cells are ignored, and
the grid does not have to be solvable or complete.
There are three rules and they are independent:
each of the 9 rows holds no repeated digit
each of the 9 columns holds no repeated digit
each of the 9 boxes holds no repeated digit
A box is one of the nine 3 by 3 squares the grid divides into. For the cell at
row r and column c, its box index is (r / 3) * 3 + (c / 3) using integer
division, and getting that expression right is most of the exercise.
Checking rows and columns and stopping is the usual wrong answer, because it accepts a grid whose only conflict is inside a box. One test here is exactly that grid: two equal digits in different rows and different columns that nonetheless share a box.
Constraints - The grid is always exactly 9 lines of 9 characters. - Each character is `1` to `9` or `.`.
Input
Nine lines, each of nine characters. Each character is a digit 1 to 9 or . for an empty cell.
Output
Print yes if no rule is broken, or no otherwise.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.