-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (41 loc) · 1.14 KB
/
main.cpp
File metadata and controls
48 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include "SudokuSolver.h"
#include "FileExporter.h"
/*
@author Oliver Klapper
This program solves a Sudoku with the help of the backtracking approach.
The program accepts a two-dimensional integer vector as input and
also delivers a two-dimensional integer vector as output,
which represents the solved Sudoku field.
*/
int main()
{
/* input sudoku field 2d vector */
Sudoku sudoku = {
{2,0,0,4,0,0,0,1,6},
{1,0,0,0,0,2,3,0,0},
{0,9,5,0,0,0,0,7,0},
{0,0,0,0,8,0,0,0,0},
{0,0,1,9,0,5,6,0,0},
{0,0,0,0,2,0,0,0,0},
{0,7,0,0,0,0,1,8,0},
{0,0,9,2,0,0,0,0,3},
{3,5,0,0,0,6,0,0,2}
};
SudokuSolver ssolver(sudoku);
std::cout << "unsolved sudoku: " << std::endl;
// print input sudoku in unresolved state
ssolver.printSudoku();
// solve sudoku and print result
if (ssolver.solveSudoku())
{
std::cout << "solved sudoku: " << std::endl;
ssolver.printSudoku();
// write sudoku result to csv file
std::ofstream of("sudokuSolution.csv");
FileExporter<int> fexporter(of);
fexporter.exportAsCSV(ssolver.getSolution(), ';');
}
return 0;
}