#include "sudoku.h" sudoku::sudoku(const int initial_a[n][n]) { for (size_t x = 0; x < n; ++x) { for (size_t y = 0; y < n; ++y) { box& r = a[y][x]; r.p = this; r.x = x; r.y = y; } } for (size_t x = 0; x < n; ++x) { col& r = cols[x]; r.p = this; r.x = x; } for (size_t y = 0; y < n; ++y) { row& r = rows[y]; r.p = this; r.y = y; } for (size_t x = 0; x < root; ++x) { for (size_t y = 0; y < root; ++y) { reg& r = regs[y][x]; r.p = this; r.x = x; r.y = y; } } for (size_t x = 0; x < n; ++x) { for (size_t y = 0; y < n; ++y) { if (const int i = initial_a[y][x]) { assert(1 <= i && i <= n); a[y][x].set(i - 1); } } } } ostream& operator<<(ostream& ost, const sudoku& s) { for (size_t y = 0; y < sudoku::n; ++y) { for (size_t x = 0; x < sudoku::n; ++x) { cout << s.a[y][x] << " "; if (x % sudoku::root == sudoku::root - 1) { cout << " "; } } cout << "\n"; if (y % sudoku::root == sudoku::root - 1 && y != sudoku::n - 1) { cout << "\n"; } } return ost; }