fn find_least_underconstrained_cell(grid: &Grid) -> (CellId, usize) {
        fn count_true(values: &[bool]) -> usize {
            values.iter().filter(|&&b| b).count()
        }
        let (choices, cell) = grid.cells()
                                  // We swap order so min sorts correctly
                                  .map(|(cell_id, values)| (count_true(values), cell_id))
                                  .filter(|&(choices, _)| choices != 1)
                                  .min()
                                  .unwrap_or((1, CellId(0)));
        (cell, choices)
    }
// Try to find a good cell to guess values for, returning it and the number possible values it might have.
// If any cells lack possibilities, return that. (no point guessing if a puzzle can't be solved)
// Else, if any cells have at least two possibilies, choose one with the a minimal number of possibilities
// Else, the puzzle is solved and it doesn't matter which cell we return.
Try to find a good cell to guess values for, returning it and the number possible values it might have.
If any cells lack possibilities, return that. (no point guessing if a puzzle can't be solved)
Else, if any cells have at least two possibilies, choose one with the a minimal number of possibilities
Else, the puzzle is solved and it doesn't matter which cell we return.
Try to find a good cell to guess values for returning it and the number possible values it might have . If any cells lack possibilities return that . ( no point guessing if a puzzle can ' t be solved ) Else if any cells have at least two possibilies choose one with the a minimal number of possibilities Else the puzzle is solved and it doesn ' t matter which cell we return .
fn find_least_underconstrained_cell(grid: &Grid) -> (CellId, usize) {
        fn count_true(values: &[bool]) -> usize {
            values.iter().filter(|&&b| b).count()
        }
        let (choices, cell) = grid.cells()
                                  // We swap order so min sorts correctly
                                  .map(|(cell_id, values)| (count_true(values), cell_id))
                                  .filter(|&(choices, _)| choices != 1)
                                  .min()
                                  .unwrap_or((1, CellId(0)));
        (cell, choices)
    }
fn find_least_underconstrained_cell ( grid : & Grid ) -> ( CellId , usize ) { fn count_true ( values : & [ bool ] ) -> usize { values . iter ( ) . filter ( | & & b | b ) . count ( ) } let ( choices , cell ) = grid . cells ( ) // We swap order so min sorts correctly . map ( | ( cell_id , values ) | ( count_true ( values ) , cell_id ) ) . filter ( | & ( choices , _ ) | choices != 1 ) . min ( ) . unwrap_or ( ( 1 , CellId ( 0 ) ) ) ; ( cell , choices ) }
Try to find a good cell to guess values for, returning it and the number possible values it might have.
Try to find a good cell to guess values for returning it and the number possible values it might have .
grid
&Grid
grid
&Grid