46 std::vector<std::vector<int>> puzzle(9, std::vector<int>(9));
49 std::ifstream infile(filepath);
51 std::string puzzledata =
"";
53 if( infile.is_open() )
55 std::getline( infile, puzzledata );
56 if( puzzledata.length() != 81 )
58 std::cerr <<
"Please check the puzzle file forinconsistencies" 66 for(
int i = 0; i < 9; ++i )
68 for(
int j = 0; j < 9; ++j )
71 if( (puzzledata.substr(idx, 1) !=
".") && (puzzledata.substr(idx, 1) !=
"0") )
73 puzzle[i][j] = std::stoi( puzzledata.substr(idx, 1) );
88 inline void printSudoku(
const std::vector<std::vector<int>> &sudokupuzzle )
90 std::cout <<
"+----------+-----------+-----------+" <<
"\n";
91 for(
int i = 0; i < 9; ++i )
94 for(
int j = 0; j < 9; ++j )
96 if( sudokupuzzle[i][j] > 0 )
99 if( j == 2 || j == 5 || j == 8 )
101 std::cout << sudokupuzzle[i][j] <<
" | ";
105 std::cout << sudokupuzzle[i][j] <<
" ";
110 if( j == 2 || j == 5 || j == 8 )
112 std::cout <<
"*" <<
" | ";
116 std::cout <<
"*" <<
" ";
122 if( i == 2 || i == 5 || i == 8 )
124 std::cout <<
"+----------+-----------+-----------+" <<
"\n";
std::vector< std::vector< int > > getSudokuPuzzle(std::string &filepath)
void printSudoku(const std::vector< std::vector< int >> &sudokupuzzle)