Skip to content

Commit ff2d110

Browse files
committed
fixed error with forgotten check for RL diagonal in 8 queens
1 parent e5452fb commit ff2d110

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

shared/src/test/scala/gopher/monads/Queens.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class QueensSuite extends FunSuite {
1919
case class State(
2020
busyRows:Set[Int],
2121
busyColumns:Set[Int],
22-
busyDiagonals:Set[Int],
22+
busyLRDiagonals:Set[Int],
23+
busyRLDiagonals:Set[Int],
2324
queens: Set[(Int,Int)]
2425
);
2526

@@ -31,12 +32,14 @@ class QueensSuite extends FunSuite {
3132
for{
3233
i <- 0 until N if !state.busyRows.contains(i)
3334
j <- 0 until N if !state.busyColumns.contains(j) &&
34-
!(state.busyDiagonals.contains(i-j))
35+
!state.busyLRDiagonals.contains(i-j) &&
36+
!state.busyRLDiagonals.contains(i+j)
3537
} {
3638
val newPos = (i,j)
3739
val nState = state.copy( busyRows = state.busyRows + i,
3840
busyColumns = state.busyColumns + j,
39-
busyDiagonals = state.busyDiagonals + (i-j),
41+
busyLRDiagonals = state.busyLRDiagonals + (i-j),
42+
busyRLDiagonals = state.busyRLDiagonals + (i+j),
4043
queens = state.queens + newPos )
4144
ch.write(nState)
4245
}
@@ -53,7 +56,7 @@ class QueensSuite extends FunSuite {
5356
state
5457
}
5558

56-
val emptyState = State(Set.empty, Set.empty, Set.empty, Set.empty)
59+
val emptyState = State(Set.empty, Set.empty, Set.empty, Set.empty, Set.empty)
5760

5861
test("first solution for 8 queens problem") {
5962
async[Future] {
@@ -64,5 +67,4 @@ class QueensSuite extends FunSuite {
6467
}
6568

6669

67-
6870
}

0 commit comments

Comments
 (0)