diff --git a/Algorithms/kotlin/Game_Theory-Tower_Breakers.kt b/Algorithms/kotlin/Game_Theory-Tower_Breakers.kt new file mode 100644 index 0000000..723b87b --- /dev/null +++ b/Algorithms/kotlin/Game_Theory-Tower_Breakers.kt @@ -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) { + 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) + } +} diff --git a/README.md b/README.md index b6b1828..67b0323 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +- Game_Theory-Game_of_Stones.kt +- Game_Theory-Tower_Breakers.kt \ No newline at end of file