Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Algorithms/kotlin/Game_Theory-Tower_Breakers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.*
import kotlin.io.*
import kotlin.text.*

fun towerBreakers(n: Int, m: Int): Int {

// 1-1. 높이가 1인 타워는 player2가 승리한다.
// 1-2. 타워의 개수가 홀수이면 player1이 승리한다.
return if ((m == 1) or (n % 2 == 0)) 2
else 1
}

fun main(args: Array<String>) {
val scan = Scanner(System.`in`)

val t = scan.nextLine().trim().toInt()

for (tItr in 1..t) {
val nm = scan.nextLine().split(" ")
val n = nm[0].trim().toInt()
val m = nm[1].trim().toInt()

val result = towerBreakers(n, m)
println(result)
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ All about hackerrank
- Bit_Manipulation-Lonely_Integer.kt
- Bit_Manipulation-Maximizing_XOR.kt
- Bit_Manipulation-Sum_vs_XOR.kt
- Game_Theory-Game_of_Stones.kt
- Game_Theory-Game_of_Stones.kt
- Game_Theory-Tower_Breakers.kt