37 std::vector<std::vector<int>> puzzle(9, std::vector<int>(9));
40 std::ifstream infile(filepath);
42 std::string puzzledata =
"";
44 if( infile.is_open() )
46 std::getline( infile, puzzledata );
47 if( puzzledata.length() != 81 )
49 std::cerr <<
"Please check the puzzle file forinconsistencies" 57 for(
int i = 0; i < 9; ++i )
59 for(
int j = 0; j < 9; ++j )
62 if( (puzzledata.substr(idx, 1) !=
".") && (puzzledata.substr(idx, 1) !=
"0") )
64 puzzle[i][j] = std::stoi( puzzledata.substr(idx, 1) );
79 inline void printSudoku(
const std::vector<std::vector<int>> &sudokupuzzle )
81 std::cout <<
"+----------+-----------+-----------+" <<
"\n";
82 for(
int i = 0; i < 9; ++i )
85 for(
int j = 0; j < 9; ++j )
87 if( sudokupuzzle[i][j] > 0 )
90 if( j == 2 || j == 5 || j == 8 )
92 std::cout << sudokupuzzle[i][j] <<
" | ";
96 std::cout << sudokupuzzle[i][j] <<
" ";
101 if( j == 2 || j == 5 || j == 8 )
103 std::cout <<
"*" <<
" | ";
107 std::cout <<
"*" <<
" ";
113 if( i == 2 || i == 5 || i == 8 )
115 std::cout <<
"+----------+-----------+-----------+" <<
"\n";
std::vector< std::vector< int > > getSudokuPuzzle(std::string &filepath)
void printSudoku(const std::vector< std::vector< int >> &sudokupuzzle)