Skip to content

Commit 4a1f66d

Browse files
committed
Simplified Sudoku::generate_incrementally().
1 parent c4e57bb commit 4a1f66d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{EMPTY, Sudoku};
2+
use rand::prelude::ThreadRng;
23
use rand::seq::SliceRandom;
34

45
impl Sudoku {
@@ -93,7 +94,7 @@ impl Sudoku {
9394
/// and finally removes cells while ensuring a unique solution.
9495
/// The `filled_cells` parameter specifies how many cells should remain filled.
9596
pub fn generate_diagonal_fill(filled_cells: usize) -> Option<Self> {
96-
let mut rng = rand::rng();
97+
let mut rng: ThreadRng = rand::rng();
9798
let mut all_digits: Vec<u8> = (1..=9).collect();
9899
let mut sudoku = Sudoku::new();
99100
// Fill the 3 diagonal boxes (top-left, middle, bottom-right)
@@ -110,7 +111,6 @@ impl Sudoku {
110111
// Get all filled cells that haven't been removed yet
111112
let mut available_cells: Vec<(usize, usize)> = (0..9)
112113
.flat_map(|row| (0..9).map(move |col| (row, col)))
113-
.filter(|&(row, col)| sudoku.board[row][col] != EMPTY)
114114
.collect();
115115
available_cells.shuffle(&mut rng);
116116
available_cells.truncate(81 - filled_cells);

0 commit comments

Comments
 (0)