Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 4, 2024
1 parent e68bc76 commit 3c3b997
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/main/kotlin/p30xx/Problem3001.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package p30xx

import util.expect

fun main() {
class Solution {
fun minMovesToCaptureTheQueen(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Int {
arrayOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1).forEach { (deltaX, deltaY) ->
var rookX = a
var rookY = b

while (rookX in 1..8 && rookY in 1..8) {
when {
rookX == c && rookY == d -> {
break
}

rookX == e && rookY == f -> {
return 1
}

else -> {
rookX += deltaX
rookY += deltaY
}
}
}
}


arrayOf(-1 to -1, -1 to 1, 1 to -1, 1 to 1).forEach { (deltaX, deltaY) ->
var bishopX = c
var bishopY = d

while (bishopX in 1..8 && bishopY in 1..8) {
when {
bishopX == a && bishopY == b -> {
break
}

bishopX == e && bishopY == f -> {
return 1
}

else -> {
bishopX += deltaX
bishopY += deltaY
}
}
}
}

return 2
}
}

expect(0) {
Solution().minMovesToCaptureTheQueen(
9, 1, 1, 1, 1, 1
)
}
}

0 comments on commit 3c3b997

Please sign in to comment.