typedef int[][] boardtype;

typedef struct {int x, int y} point;
bool finished = false;

void backtrack_sudoku(pt, value, board);
  // if point is beyond board, we're done, report result.
  // if pt is occupied (by input value) go to next point
  // if it is valid, commit to the move and try to complete solution
  // but if this is last value (9), backtrack

void backtrack_sudoku(point pt, int value, boardtype board) {
  // pt, value denotes a potential next move
  // if point is beyond board, we're done, report result.
  if (done(pt)) 
  {	process_solution(board); finished = true; }
  // if pt is occupied (by input value) go to next point
  else if (board[pt.x][pt.y] > 0)
    backtrack_sudoku(next_point(pt), 1, board)
  else 
  {  // if it is valid, use it and continue to next point, value 1
    if (valid(pt, value, board))
      board[pt.x][pt.y] = value; // make move
      backtrack_sudoku(next_point(pt), 1, board);
      board[pt.x][pt.y] = 0; // unmake move
    // if it is invalid or valid but didn't yield a complete solution, continue to next value
    if ( !finished && value < 9)
        backtrack_sudoku(pt, value+1, board);
  }
  // but if this is last value (9), backtrack
}

point next_point(point pt) {
	Point next = pt;
	if (next.y < 9) next.y += 1;
    else {next.y = 1; next.x += 1;
	return next;
}

bool done(point p) { return p.x > 9; }

bool valid(point p, int value, boardtype board) {
//check row: that for each j board[pt.x][j] != value 
//check col: that for each i board[i][pt.y] != value 
//check block: that for each i,j in 3 by 3 block of point, board[i][j] != value
}

process_solution(boardtype board) {
	printf{"Solved!");
}
