Skip to content

Commit c9f3661

Browse files
DaveAxiomsiriak
andauthored
Fix N-Queens (TheAlgorithms#253)
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
1 parent a0eb41d commit c9f3661

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ RESTART BUILD
7575
## [General](./src/general)
7676

7777
- [x] [Convex Hull: Graham Scan](./src/general/convex_hull.rs)
78-
- [ ] N-Queensp
78+
- [x] [N-Queens Problem](./src/general/nqueens.rs)
7979
- [ ] Graph Coloringp
8080
- [x] [Tower of Hanoi](./src/general/hanoi.rs)
8181
- [x] [Kmeans](./src/general/kmeans.rs)

src/general/nqueens.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@ pub fn nqueens(board_width: i64) -> Result<Vec<i64>, &'static str> {
6262
}
6363
}
6464

65-
match (current_row, conflict) {
66-
(0, false) => current_row = 1,
67-
(_, true) => {
65+
match conflict {
66+
true => {
6867
board_rows[current_row] += 1;
6968

7069
if current_row == 0 && board_rows[current_row] == board_width {
7170
return Err("No solution exists for specificed board size.");
7271
}
7372

74-
//Run in while's condition evaluation to create a "do while"
7573
while board_rows[current_row] == board_width {
7674
board_rows[current_row] = 0;
7775

@@ -83,7 +81,7 @@ pub fn nqueens(board_width: i64) -> Result<Vec<i64>, &'static str> {
8381
board_rows[current_row] += 1;
8482
}
8583
}
86-
(_, _) => {
84+
_ => {
8785
current_row += 1;
8886

8987
if current_row as i64 == board_width {

0 commit comments

Comments
 (0)