|
| 1 | +/* A basic example. */ |
| 2 | + |
| 3 | +#include<iostream> |
| 4 | +#include"../src/sudoku_suite.h" |
| 5 | + |
| 6 | +int main() { |
| 7 | + // Method 1: Use the constructor and pass in a |
| 8 | + // 2D matrix of values. |
| 9 | + sudoku::Grid grid({{ |
| 10 | + {{ 0, 0, 0, 0, 0, 0, 6, 8, 0 }}, |
| 11 | + {{ 0, 0, 0, 0, 7, 3, 0, 0, 9 }}, |
| 12 | + {{ 3, 0, 9, 0, 0, 0, 0, 4, 5 }}, |
| 13 | + {{ 4, 9, 0, 0, 0, 0, 0, 0, 0 }}, |
| 14 | + {{ 8, 0, 3, 0, 5, 0, 9, 0, 2 }}, |
| 15 | + {{ 0, 0, 0, 0, 0, 0, 0, 3, 6 }}, |
| 16 | + {{ 9, 6, 0, 0, 0, 0, 3, 0, 8 }}, |
| 17 | + {{ 7, 0, 0, 6, 8, 0, 0, 0, 0 }}, |
| 18 | + {{ 0, 2, 8, 0, 0, 0, 0, 0, 0 }} |
| 19 | + }}); |
| 20 | + std::cout << grid << std::endl; |
| 21 | + |
| 22 | + // Method 2: Declare a 2D array and pass it |
| 23 | + // into the set_initial_state() method. |
| 24 | + |
| 25 | + std::array<std::array<int, 9>, 9> values = {{ |
| 26 | + {{ 9, 7, 8, 4, 1, 0, 0, 0, 5 }}, |
| 27 | + {{ 3, 0, 0, 8, 0, 0, 0, 6, 4 }}, |
| 28 | + {{ 6, 0, 0, 3, 5, 0, 0, 9, 0 }}, |
| 29 | + {{ 2, 6, 9, 0, 3, 0, 0, 0, 7 }}, |
| 30 | + {{ 5, 0, 7, 1, 0, 0, 0, 0, 0 }}, |
| 31 | + {{ 1, 0, 3, 0, 0, 2, 0, 8, 9 }}, |
| 32 | + {{ 7, 1, 0, 2, 0, 5, 0, 0, 3 }}, |
| 33 | + {{ 0, 0, 2, 7, 0, 3, 1, 5, 8 }}, |
| 34 | + {{ 0, 0, 5, 9, 4, 1, 0, 0, 0 }} |
| 35 | + }}; |
| 36 | + grid.set_initial_state(values); |
| 37 | + std::cout << grid << std::endl; |
| 38 | + |
| 39 | + // Method 3: Read the initial state of the puzzle |
| 40 | + // from a file. |
| 41 | + |
| 42 | + grid.set_initial_state_from_file("samples/sample1.txt"); |
| 43 | + std::cout << grid << std::endl; |
| 44 | + |
| 45 | + return 0; |
| 46 | +} |
0 commit comments