fn find_solution<W: Write>(mut b: Board, vkey_max: usize, hkey_max: usize, mut stdout: W) -> bool {
    b.size.swap(0, 1);
    b.solve();
    let mut grid = Vec::new();
    let mut guess = Vec::new();
    grid.push(b);
    guess.push(None);
    while !grid.is_empty() {
        let a_grid = grid.last().unwrap();
        if !a_grid.valid_grid() {
            grid.pop();
            guess.pop();
            continue;
        }
        if a_grid.complete_grid() {
            a_grid.update_board(&mut stdout, &vkey_max, &hkey_max);
            stdout.flush().unwrap();
            return true;
        }
        if let Some((_, Status::Marked)) = guess.last().unwrap() {
            grid.pop();
            guess.pop();
            continue;
        }

        let a_guess = guess.last_mut().unwrap();
        if a_guess.is_none() {
            let (i, j) = a_grid.get_unknown_cell();
            *a_guess = Some(((i, j), Status::Empty));
            let mut new_grid = a_grid.clone();
            new_grid.grid[i][j].cell_state = Status::Empty;
            new_grid.solve();
            grid.push(new_grid);
            guess.push(None);
        } else {
            let (i, j) = a_grid.get_unknown_cell();
            *a_guess = Some(((i, j), Status::Marked));
            let mut new_grid = a_grid.clone();
            new_grid.grid[i][j].cell_state = Status::Marked;
            new_grid.solve();
            new_grid.solve();
            grid.push(new_grid);
            guess.push(None);
        }
    }
    false
}
//solves the given puzzle using deductive methods until no more deductions are possible
//once deductive reasoning cannot be used, make a guess, check whether the guess makes for a valid solution
//if valid, keep using deduction, otherwise, pop from the stack and make another guess
solves the given puzzle using deductive methods until no more deductions are possible
once deductive reasoning cannot be used, make a guess, check whether the guess makes for a valid solution
if valid, keep using deduction, otherwise, pop from the stack and make another guess
solves the given puzzle using deductive methods until no more deductions are possible once deductive reasoning cannot be used make a guess check whether the guess makes for a valid solution if valid keep using deduction otherwise pop from the stack and make another guess
fn find_solution<W: Write>(mut b: Board, vkey_max: usize, hkey_max: usize, mut stdout: W) -> bool {
    b.size.swap(0, 1);
    b.solve();
    let mut grid = Vec::new();
    let mut guess = Vec::new();
    grid.push(b);
    guess.push(None);
    while !grid.is_empty() {
        let a_grid = grid.last().unwrap();
        if !a_grid.valid_grid() {
            grid.pop();
            guess.pop();
            continue;
        }
        if a_grid.complete_grid() {
            a_grid.update_board(&mut stdout, &vkey_max, &hkey_max);
            stdout.flush().unwrap();
            return true;
        }
        if let Some((_, Status::Marked)) = guess.last().unwrap() {
            grid.pop();
            guess.pop();
            continue;
        }
        let a_guess = guess.last_mut().unwrap();
        if a_guess.is_none() {
            let (i, j) = a_grid.get_unknown_cell();
            *a_guess = Some(((i, j), Status::Empty));
            let mut new_grid = a_grid.clone();
            new_grid.grid[i][j].cell_state = Status::Empty;
            new_grid.solve();
            grid.push(new_grid);
            guess.push(None);
        } else {
            let (i, j) = a_grid.get_unknown_cell();
            *a_guess = Some(((i, j), Status::Marked));
            let mut new_grid = a_grid.clone();
            new_grid.grid[i][j].cell_state = Status::Marked;
            new_grid.solve();
            new_grid.solve();
            grid.push(new_grid);
            guess.push(None);
        }
    }
    false
}
fn find_solution < W : Write > ( mut b : Board , vkey_max : usize , hkey_max : usize , mut stdout : W ) -> bool { b . size . swap ( 0 , 1 ) ; b . solve ( ) ; let mut grid = Vec :: new ( ) ; let mut guess = Vec :: new ( ) ; grid . push ( b ) ; guess . push ( None ) ; while ! grid . is_empty ( ) { let a_grid = grid . last ( ) . unwrap ( ) ; if ! a_grid . valid_grid ( ) { grid . pop ( ) ; guess . pop ( ) ; continue ; } if a_grid . complete_grid ( ) { a_grid . update_board ( & mut stdout , & vkey_max , & hkey_max ) ; stdout . flush ( ) . unwrap ( ) ; return true ; } if let Some ( ( _ , Status :: Marked ) ) = guess . last ( ) . unwrap ( ) { grid . pop ( ) ; guess . pop ( ) ; continue ; } let a_guess = guess . last_mut ( ) . unwrap ( ) ; if a_guess . is_none ( ) { let ( i , j ) = a_grid . get_unknown_cell ( ) ; * a_guess = Some ( ( ( i , j ) , Status :: Empty ) ) ; let mut new_grid = a_grid . clone ( ) ; new_grid . grid [ i ] [ j ] . cell_state = Status :: Empty ; new_grid . solve ( ) ; grid . push ( new_grid ) ; guess . push ( None ) ; } else { let ( i , j ) = a_grid . get_unknown_cell ( ) ; * a_guess = Some ( ( ( i , j ) , Status :: Marked ) ) ; let mut new_grid = a_grid . clone ( ) ; new_grid . grid [ i ] [ j ] . cell_state = Status :: Marked ; new_grid . solve ( ) ; new_grid . solve ( ) ; grid . push ( new_grid ) ; guess . push ( None ) ; } } false }
solves the given puzzle using deductive methods until no more deductions are possible
once deductive reasoning cannot be used, make a guess, check whether the guess makes for a valid solution
if valid, keep using deduction, otherwise, pop from the stack and make another guess
solves the given puzzle using deductive methods until no more deductions are possible once deductive reasoning cannot be used make a guess check whether the guess makes for a valid solution if valid keep using deduction otherwise pop from the stack and make another guess
b
Board
vkey_max
usize
hkey_max
usize
stdout
W
b
Board
vkey_max
usize
hkey_max
usize
stdout
W