netfri25 / sudoku-solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple sudoku solver written in Rust.

Changing the board

In the main file, you can build a board using the BoardBuilder. You can create the board like this:

fn main() {
   let mut board = BoardBuilder::new()
      .insert((0,0), 3)
      .insert((0,4), 6)
      .insert((3,5), 2)
      .build(); // you must call the build function at the end of the building process.

   if board.solve() {
      println!("the board has been solved successfully!");
      println!("{:?}", board)
   } else {
      println!("failed to solve the board :sad:")
   }
}

or like this:

fn main() {
   let mut board = BoardBuilder::from([
      [3,0,0,0,6,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,2,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0],
   ]).build() // same here, you must call the build function.

   if board.solve() {
      println!("the board has been solved successfully!");
      println!("{:?}", board)
   } else {
      println!("failed to solve the board :sad:")
   }
}

both of them do the same exact thing, but in my opinion the first option is more handy.

Running the code

You must have cargo installed. then in your shell, navigate to this project folder and run:

cargo run --release

this should compile and execute the program.

TODO:

  • add GUI and graphics.
  • add option to load boards from a file.
  • don't forget to complete the TODO list.

About


Languages

Language:Rust 100.0%