https://github.com/cyberark/sudoku-validator
A very refactor-able Sudoku puzzle solution validator.
https://github.com/cyberark/sudoku-validator
conjbot-notify
Last synced: 29 days ago
JSON representation
A very refactor-able Sudoku puzzle solution validator.
- Host: GitHub
- URL: https://github.com/cyberark/sudoku-validator
- Owner: cyberark
- License: apache-2.0
- Created: 2019-10-29T17:41:15.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-13T16:08:38.000Z (over 3 years ago)
- Last Synced: 2024-06-12T04:52:48.973Z (12 months ago)
- Topics: conjbot-notify
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 22
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Sudoku Validator
The Sudoku Validator library provides a mechanism for validating a Sudoku solution.
## Valid Solutions
A valid Sudoku solution is one in which the number one through nine appears only once in each vertical row, horizontal row, and square.## Input
The `SudokuValidator` class takes a multi-line string with a solved solution:A valid solution:
```
4 3 5 | 2 6 9 | 7 8 1
6 8 2 | 5 7 1 | 4 9 3
1 9 7 | 8 3 4 | 5 6 2
------+------+------
8 2 6 | 1 9 5 | 3 4 7
3 7 4 | 6 8 2 | 9 1 5
9 5 1 | 7 4 3 | 6 2 8
------+------+------
5 1 9 | 3 2 6 | 8 7 4
2 4 8 | 9 5 7 | 1 3 6
7 6 3 | 4 1 8 | 2 5 9
```An invalid solution (the number `3` appears multiple times in the horizontal, vertical, and square):
```
3 3 5 | 2 6 9 | 7 8 1
3 8 2 | 5 7 1 | 4 9 3
1 9 7 | 8 3 4 | 5 6 2
------+------+------
8 2 6 | 1 9 5 | 3 4 7
3 7 4 | 6 8 2 | 9 1 5
9 5 1 | 7 4 3 | 6 2 8
------+------+------
5 1 9 | 3 2 6 | 8 7 4
2 4 8 | 9 5 7 | 1 3 6
7 6 3 | 4 1 8 | 2 5 9
```## Development
The SudokuValidator library is written in Ruby. The only development requirement is having Ruby 2.0 or greater available on your system.### Testing
Tests for the SudokuValidator are written using MiniTest, using the Spec style. Tests can run with:
```
$ ruby sudoku_validator_spec.rb
```