You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are a suite of C++ programs which deal with Sudoku Puzzles. The name might be misleading, yes, but these programs don't just solve Sudoku puzzles, they also achieve other objectives such as Sudoku Puzzle Validation and Sudoku Puzzle Generation (Under development).
1
+
# Sudoku-Suite
2
+
A C++17-compatible header that provides useful functions which help with the solving, validation and generation of 9x9 Sudoku puzzles.
3
3
4
4
## Contents
5
-
*[Sudoku Solver](#sudoku-solver)
6
-
*[Getting Started (Usage)](#getting-started)
7
-
*[How It Works](#how-it-works)
8
-
*[Sudoku Validator](#sudoku-validator)
9
-
*[Getting Started (Usage)](#getting-started-1)
10
-
*[How It Works](#how-it-works-1)
5
+
*[Usage](#usage)
6
+
*[Documentation](#documentation)
7
+
*[Examples](#examples)
8
+
*[Solving and validating a Sudoku puzzle](#solving-and-validating-sudoku-puzzle)
9
+
*[Generating a Sudoku puzzle](#generating-a-sudoku-puzzle)
10
+
*[Initialising and reusing Grid objects](#initialising-and-reusing-grid-objects)
11
+
*[Reading Sudoku puzzles from a file](#reading-sudoku-puzzles-from-a-file)
12
+
*[Operations on Grid objects](#operations-on-grid-objects)
13
+
*[How It Works](#sudoku-solver---how-it-works)
11
14
*[Acknowledgements](#acknowledgements)
12
15
*[Tools](#tools)
13
16
14
-
# Sudoku-Solver
15
-
This is a program which solves 9x9 Sudoku puzzles. **Written completely in C++** and **built wholly from scratch**, this program reads input either from a user or from a file containing the Sudoku values and solves the puzzle. It employs concepts such as backtracking and recursion.
16
-
17
-
### Getting Started
18
-
* Simply download the ```sudoku-solver.cpp``` file found in the ```Sudoku-Solver/``` directory. Run it using any standard C++ compiler. In case of any errors or compatibility issues, submit an issue in this git.
19
-
* Once downloaded, compiled and run; the program will require the user to input the Sudoku puzzle into it. There are two ways to do this.
20
-
* The user can either input the values manually one-by-one when the program is running.
21
-
* The user can write all the values into a file, seperated by whitespaces. The file can have any name or extension. When the program is running, the user will be prompted to simply enter the name of the file (with extension). **Below** is an example of how the contents of such a file might look. Look at the ```sample.txt``` files in the same directory for more examples.
17
+
## Usage
18
+
19
+
* Simply download the `src/sudoku_suite.h` file and move it to your project's directory.
20
+
* Include the header file, as shown below in the examples, and use the functions you need!
21
+
***NOTE:** The code is incompatible with pre-C++17 versions. While compiling, you'll have to compile with the `--std=c++17` flag.
22
+
* For example; when using the clang compiler, the compile command would be `c++ --std=c++17 /path/to/file.cpp`
23
+
24
+
## Documentation
25
+
26
+
There are **three functions** that Sudoku-Suite provides the developer, along with **one class**. They are as follows:-
27
+
28
+
*`Grid`
29
+
* An object that represents a 9x9 Sudoku grid. The `Grid` object does not validate the grid in any way, i.e, it only holds the grid and values inside it.
30
+
* While initialising, if the given values are invalid, an `std::invalid_argument` exception is thrown.
31
+
**Check out the examples below to see how we can initialise and use this object!*
32
+
*`void solve(Grid *grid)`
33
+
* A function that takes in a pointer to a `Grid` object and solves the Sudoku puzzle present in it. Returns nothing.
34
+
* If the puzzle cannot be solved, a `std::logic_error` exception is thrown.
35
+
*`bool is_valid_solution(Grid &grid)`
36
+
* A function that takes in a `Grid` object and returns a `bool` with a value of `true` if the `Grid` object contains a finished and valid Sudoku solution.
37
+
*`Grid generate_puzzle()`
38
+
* A function that takes in nothing and returns a `Grid` object containing an unfinished Sudoku puzzle.
39
+
40
+
## Examples
41
+
42
+
**NOTE:** The following examples are also present in the repository in the `samples/` directory.
43
+
44
+
*[Solving and validating a Sudoku puzzle](#solving-and-validating-sudoku-puzzle)
45
+
*[Generating a Sudoku puzzle](#generating-a-sudoku-puzzle)
46
+
*[Initialising and reusing Grid objects](#initialising-and-reusing-grid-objects)
47
+
*[Reading Sudoku puzzles from a file](#reading-sudoku-puzzles-from-a-file)
48
+
*[Operations on Grid objects](#operations-on-grid-objects)
This particular algorithm employs the use of backtracking, one of the more common methods to solve Sudoku puzzles. I've written a simple algorithm to give an idea of how the program works.
62
224
63
225
1. Start.
@@ -69,47 +231,6 @@ This particular algorithm employs the use of backtracking, one of the more commo
69
231
7. The puzzle has now been solved.
70
232
8. Stop.
71
233
72
-
# Sudoku Validator
73
-
This is a program which validates solutions for 9x9 Sudoku puzzles. **Written completely in C++** and **built wholly from scratch**, this program takes in input from the user or from a file containing the values. It then validates the puzzle and then displays whether it is a valid solution or not.
74
-
75
-
### Getting Started
76
-
* Simply download the ```sudoku-validator.cpp``` file found in the ```Sudoku-Validator``` directory. Run it using any standard C++ compiler. In case of any errors or compatibility issues, submit an issue in this git.
77
-
* Once downloaded, compiled and run; the program will require the user to input the Sudoku puzzle into it. There are two ways to do this.
78
-
* The user can either input the values manually one-by-one when the program is running.
79
-
* The user can write all the values into a file, seperated by whitespaces. The file can have any name or extension. When the program is running, the user will be prompted to simply enter the name of the file (with extension). **Below** is an example of how the contents of such a file might look. Look at the ```sample.txt``` files in the same directory for more examples.
80
-
81
-
```
82
-
8 4 6 9 3 7 1 5 2
83
-
3 1 9 6 2 5 8 4 7
84
-
7 5 2 1 8 4 9 6 3
85
-
86
-
2 8 5 7 1 3 6 9 4
87
-
4 6 3 8 5 9 2 7 1
88
-
9 7 1 2 4 6 3 8 5
89
-
90
-
1 2 7 5 9 8 4 3 6
91
-
6 3 8 4 7 1 5 2 9
92
-
5 9 4 3 6 2 7 1 8
93
-
```
94
-
95
-
96
-
### How It Works
97
-
The workings of the Sudoku Validator are quite simple, to be honest. Here's a simple algorithm explaining them all.
98
-
99
-
1. Start
100
-
2. The values in all the cells are checked to see if they are in the range 1-9. If not, the puzzle is invalid.
101
-
3. Every row is checked to see if it contains 1-9 atleast once. If not, the solution is invalid.
102
-
4. Every column is checked to see if it contains 1-9 atleast once. If not, the solution is invalid.
103
-
4. Every 3x3 grid is checked to see if it contains 1-9 atleast once. If not, the solution is invalid.
104
-
5. If all the criteria have been satisfied, the solution is valid.
105
-
6. Stop
106
-
107
-
## Future Direction
108
-
109
-
* Right now, the Sudoku Solver Suite is just a CLI application with a I/O interface. However, if we could make it into a CLI utility which takes in inputs through parameters and switches, that would make it easier for other developers to reuse.
110
-
* I was thinking we could write a "backend" which could then be called by various "interface frontends". The backend is written in C++ and the frontends could be shell or maybe an API or something.
111
-
* The objective would be for this to be used by web backends and things like that.
0 commit comments