-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample programs to demonstrate usage
- Loading branch information
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* A basic example. */ | ||
|
||
#include<iostream> | ||
#include"../src/sudoku_suite.h" | ||
|
||
int main() { | ||
sudoku::Grid grid; | ||
grid.set_initial_state_from_file("samples/sample1.txt"); | ||
std::cout << grid << std::endl; | ||
|
||
sudoku::solve(&grid); | ||
std::cout << grid << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* A basic example. */ | ||
|
||
#include<iostream> | ||
#include"../src/sudoku_suite.h" | ||
|
||
int main() { | ||
// Method 1: Use the constructor and pass in a | ||
// 2D matrix of values. | ||
sudoku::Grid grid({{ | ||
{{ 0, 0, 0, 0, 0, 0, 6, 8, 0 }}, | ||
{{ 0, 0, 0, 0, 7, 3, 0, 0, 9 }}, | ||
{{ 3, 0, 9, 0, 0, 0, 0, 4, 5 }}, | ||
{{ 4, 9, 0, 0, 0, 0, 0, 0, 0 }}, | ||
{{ 8, 0, 3, 0, 5, 0, 9, 0, 2 }}, | ||
{{ 0, 0, 0, 0, 0, 0, 0, 3, 6 }}, | ||
{{ 9, 6, 0, 0, 0, 0, 3, 0, 8 }}, | ||
{{ 7, 0, 0, 6, 8, 0, 0, 0, 0 }}, | ||
{{ 0, 2, 8, 0, 0, 0, 0, 0, 0 }} | ||
}}); | ||
std::cout << grid << std::endl; | ||
|
||
// Method 2: Declare a 2D array and pass it | ||
// into the set_initial_state() method. | ||
|
||
std::array<std::array<int, 9>, 9> values = {{ | ||
{{ 9, 7, 8, 4, 1, 0, 0, 0, 5 }}, | ||
{{ 3, 0, 0, 8, 0, 0, 0, 6, 4 }}, | ||
{{ 6, 0, 0, 3, 5, 0, 0, 9, 0 }}, | ||
{{ 2, 6, 9, 0, 3, 0, 0, 0, 7 }}, | ||
{{ 5, 0, 7, 1, 0, 0, 0, 0, 0 }}, | ||
{{ 1, 0, 3, 0, 0, 2, 0, 8, 9 }}, | ||
{{ 7, 1, 0, 2, 0, 5, 0, 0, 3 }}, | ||
{{ 0, 0, 2, 7, 0, 3, 1, 5, 8 }}, | ||
{{ 0, 0, 5, 9, 4, 1, 0, 0, 0 }} | ||
}}; | ||
grid.set_initial_state(values); | ||
std::cout << grid << std::endl; | ||
|
||
// Method 3: Read the initial state of the puzzle | ||
// from a file. | ||
|
||
grid.set_initial_state_from_file("samples/sample1.txt"); | ||
std::cout << grid << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* A basic example. */ | ||
|
||
#include<iostream> | ||
#include"../src/sudoku_suite.h" | ||
|
||
int main() { | ||
|
||
sudoku::Grid sample_grid_1({{ | ||
{{ 1, 7, 2, 5, 4, 9, 6, 8, 3 }}, | ||
{{ 6, 4, 5, 8, 7, 3, 2, 1, 9 }}, | ||
{{ 3, 8, 9, 2, 6, 1, 7, 4, 5 }}, | ||
{{ 4, 9, 6, 3, 2, 7, 8, 5, 1 }}, | ||
{{ 8, 1, 3, 4, 5, 6, 9, 7, 2 }}, | ||
{{ 2, 5, 7, 1, 9, 8, 4, 3, 6 }}, | ||
{{ 9, 6, 4, 7, 1, 5, 3, 2, 8 }}, | ||
{{ 7, 3, 1, 6, 8, 2, 5, 9, 4 }}, | ||
{{ 5, 2, 8, 9, 3, 4, 1, 6, 7 }} | ||
}}); | ||
|
||
sudoku::Grid sample_grid_2({{ | ||
{{ 1, 7, 2, 5, 4, 9, 6, 8, 3 }}, | ||
{{ 6, 4, 5, 8, 7, 3, 2, 1, 9 }}, | ||
{{ 3, 8, 9, 2, 6, 1, 7, 4, 5 }}, | ||
{{ 4, 9, 6, 3, 2, 7, 8, 5, 1 }}, | ||
{{ 8, 1, 3, 4, 5, 6, 9, 7, 2 }}, | ||
{{ 2, 5, 7, 1, 9, 8, 4, 3, 6 }}, | ||
{{ 9, 6, 4, 7, 1, 5, 3, 2, 8 }}, | ||
{{ 7, 3, 1, 6, 8, 2, 5, 9, 4 }}, | ||
{{ 5, 2, 8, 9, 3, 4, 1, 6, 7 }} | ||
}}); | ||
|
||
if (sample_grid_1 == sample_grid_2) std::cout << "They're the same! \n\n"; | ||
|
||
// Get grid value for coordinate. | ||
std::pair<int, int> last_coord = std::make_pair(8, 8); | ||
int last_value = sample_grid_1.get(last_coord); | ||
|
||
// Print the grid to the console. | ||
std::cout << sample_grid_2 << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
5 3 0 0 7 0 0 0 0 | ||
6 0 0 1 9 5 0 0 0 | ||
0 9 8 0 0 0 0 6 0 | ||
8 0 0 0 6 0 0 0 3 | ||
4 0 0 8 0 3 0 0 1 | ||
7 0 0 0 2 0 0 0 6 | ||
0 6 0 0 0 0 2 8 0 | ||
0 0 0 4 1 9 0 0 5 | ||
0 0 0 0 8 0 0 7 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* A basic example. */ | ||
|
||
#include<iostream> | ||
#include"../src/sudoku_suite.h" | ||
|
||
int main() { | ||
sudoku::Grid grid = sudoku::generate_puzzle(); | ||
std::cout << grid << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* A basic example. */ | ||
|
||
#include<iostream> | ||
#include"../src/sudoku_suite.h" | ||
|
||
int main() { | ||
sudoku::Grid grid({{ | ||
{{ 0, 0, 0, 0, 0, 0, 6, 8, 0 }}, // The 0s represent blank cells. | ||
{{ 0, 0, 0, 0, 7, 3, 0, 0, 9 }}, | ||
{{ 3, 0, 9, 0, 0, 0, 0, 4, 5 }}, | ||
{{ 4, 9, 0, 0, 0, 0, 0, 0, 0 }}, | ||
{{ 8, 0, 3, 0, 5, 0, 9, 0, 2 }}, | ||
{{ 0, 0, 0, 0, 0, 0, 0, 3, 6 }}, | ||
{{ 9, 6, 0, 0, 0, 0, 3, 0, 8 }}, | ||
{{ 7, 0, 0, 6, 8, 0, 0, 0, 0 }}, | ||
{{ 0, 2, 8, 0, 0, 0, 0, 0, 0 }} | ||
}}); | ||
|
||
sudoku::solve(&grid); | ||
|
||
std::cout << "Solution is valid? --> "; | ||
std::cout << sudoku::is_valid_solution(grid) << std::endl; | ||
std::cout << grid << std::endl; | ||
|
||
return 0; | ||
} |