From 56d2b9bb108c7415a5c5e6a070e3eaec2ca41939 Mon Sep 17 00:00:00 2001 From: EthanShin Date: Fri, 5 Jul 2019 21:21:53 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20Add=20Mis=C3=A8re=5FNim.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit description: A Nim game where you lose if you take the last stone. --- .../kotlin/Game_Theory-Mis\303\250re_Nim.kt" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" diff --git "a/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" "b/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" new file mode 100644 index 0000000..66c422c --- /dev/null +++ "b/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" @@ -0,0 +1,24 @@ +import java.util.* +import kotlin.collections.* +import kotlin.io.* +import kotlin.text.* + +fun misereNim(s: Array): String { + + return "First" +} + +fun main(args: Array) { + val scan = Scanner(System.`in`) + + val t = scan.nextLine().trim().toInt() + + for (gItr in 1..t) { + val n = scan.nextLine().trim().toInt() + + val s = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray() + + val result = misereNim(s) + println(result) + } +} \ No newline at end of file From 1b25ecdb564acf48729d809d5df2a5abf5fb9860 Mon Sep 17 00:00:00 2001 From: EthanShin Date: Fri, 5 Jul 2019 21:27:34 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20Modify=20Mis=C3=A8re=5FNim.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit description: A Nim game where you lose if you take the last stone. --- .../kotlin/Game_Theory-Mis\303\250re_Nim.kt" | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git "a/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" "b/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" index 66c422c..d2983ad 100644 --- "a/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" +++ "b/Algorithms/kotlin/Game_Theory-Mis\303\250re_Nim.kt" @@ -5,7 +5,24 @@ import kotlin.text.* fun misereNim(s: Array): String { - return "First" + // 1. 돌의 개수와 전체 pile의 개수가 같다면 모든 파일에 1개의 돌이 있는 것이다. + // 1-1. 따라서, 홀수면 Second가 승리한다. + s.reduce { acc, i -> acc + i }.let { + if (it == s.size) { + return when(it % 2) { + 0 -> "First" + else -> "Second" + } + } + } + + // 2. 일반적인 Nim game의 승자와 패자가 반대가 된다. 따라서 값이 0이면 Second가 승리한다. + s.reduce { acc, i -> acc xor i }.let { + return when(it) { + 0 -> "Second" + else -> "First" + } + } } fun main(args: Array) { From 9699602a81d765ae1e8959a665309aa50c235f6d Mon Sep 17 00:00:00 2001 From: EthanShin Date: Fri, 5 Jul 2019 21:29:06 +0900 Subject: [PATCH 3/3] docs: Modify REMOTE_README.md resolved: #114 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 a57f9c7..a98ead7 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,5 @@ All about hackerrank - Game_Theory-A_Chessboard_Game.kt - Game_Theory-Game_of_Stones.kt - Game_Theory-Introduction_to_Nim_Game.kt +- Game_Theory-Misère_Nim.kt - Game_Theory-Tower_Breakers.kt \ No newline at end of file