Write code to check if a given string is a correct sudoku puzzle and return a message indicating whether the puzzle is valid, invalid or valid and incomplete.
After cloning the repository, run the following command:
bin/setup
The program can be run via rake run
:
rake run <path to the sudoku file to validate>
Depending on the contents of the sudoku puzzle, the program should return a different result
- If the puzzle is valid and completed, return
Sudoku is valid.
- If the puzzle is valid but not fully completed, return
Sudoku is valid but incomplete.
- If the puzzle is not valid, return
Sudoku is invalid.
A puzzle is valid if:
- No numbers are repeated in any of the rows
- No numbers are repeated in any of the columns
- Every 9x9 square has no repeated numbers
- Only numbers 1 - 9 are used to fill the puzzle (or 0 for empty cells)
Additions should be written to lib/validator.rb
within the method validate
, the creation of additional methods and classes is encouraged.
This exercise contains unit tests that verify that the solution functions correctly. If all of the tests pass, the solution is correct.
The tests can be run via rake spec
.
Zeroes represent empty sudoku cells
8 5 0 |0 0 2 |4 0 0
7 2 0 |0 0 0 |0 0 9
0 0 4 |0 0 0 |0 0 0
------+------+------
0 0 0 |1 0 7 |0 0 2
3 0 5 |0 0 0 |9 0 0
0 4 0 |0 0 0 |0 0 0
------+------+------
0 0 0 |0 8 0 |0 7 0
0 1 7 |0 0 0 |0 0 0
0 0 0 |0 3 6 |0 4 0