From d0974e6b836709843f375abb7892dd0d5e8e076c Mon Sep 17 00:00:00 2001 From: EthanShin Date: Sat, 6 Jul 2019 23:45:19 +0900 Subject: [PATCH 1/3] feat: Add Nimble_Game.kt description: Given the value of n and the number of coins in each square, determine whether the person who wins the game is the first or second person to move. Assume both players move optimally. --- Algorithms/kotlin/Game_Theory-Nimble_Game.kt | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Algorithms/kotlin/Game_Theory-Nimble_Game.kt diff --git a/Algorithms/kotlin/Game_Theory-Nimble_Game.kt b/Algorithms/kotlin/Game_Theory-Nimble_Game.kt new file mode 100644 index 0000000..f29e2ab --- /dev/null +++ b/Algorithms/kotlin/Game_Theory-Nimble_Game.kt @@ -0,0 +1,24 @@ +import java.util.* +import kotlin.collections.* +import kotlin.io.* +import kotlin.text.* + +fun nimbleGame(s: Array): String { + + return "First" +} + +fun main(args: Array) { + val scan = Scanner(System.`in`) + + val t = scan.nextLine().trim().toInt() + + for (tItr in 1..t) { + val n = scan.nextLine().trim().toInt() + + val s = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray() + + val result = nimbleGame(s) + println(result) + } +} \ No newline at end of file From e6c3e34b933af2e7d417cd7dd0b5f3a4678ae982 Mon Sep 17 00:00:00 2001 From: EthanShin Date: Sun, 7 Jul 2019 02:02:45 +0900 Subject: [PATCH 2/3] feat: Modify Nimble_Game.kt description: Given the value of n and the number of coins in each square, determine whether the person who wins the game is the first or second person to move. Assume both players move optimally. --- Algorithms/kotlin/Game_Theory-Nimble_Game.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Algorithms/kotlin/Game_Theory-Nimble_Game.kt b/Algorithms/kotlin/Game_Theory-Nimble_Game.kt index f29e2ab..268748b 100644 --- a/Algorithms/kotlin/Game_Theory-Nimble_Game.kt +++ b/Algorithms/kotlin/Game_Theory-Nimble_Game.kt @@ -5,7 +5,18 @@ import kotlin.text.* fun nimbleGame(s: Array): String { - return "First" + var nim = 0 + + // 1. 돌의 개수가 홀수인 인덱스 값을 xor하여 균형상태인지 확인한다. + s.forEachIndexed { index, i -> + if ( i % 2 == 1) { + nim = nim.xor(index) + } + } + + // 2. 균형상태라면 Second가 승리한다. + return if (nim == 0) "Second" + else "First" } fun main(args: Array) { From 2d0f13631d27b45d8994986490279d367daa2e8e Mon Sep 17 00:00:00 2001 From: EthanShin Date: Sun, 7 Jul 2019 02:04:11 +0900 Subject: [PATCH 3/3] docs: Modify REMOTE_README.md resolved: #116 description: Add a file name to the index. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a98ead7..07f3b0e 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,5 @@ All about hackerrank - Game_Theory-Game_of_Stones.kt - Game_Theory-Introduction_to_Nim_Game.kt - Game_Theory-Misère_Nim.kt +- Game_Theory-Nimble_Game.kt - Game_Theory-Tower_Breakers.kt \ No newline at end of file