Skip to content

Commit 4e1f1e0

Browse files
author
openset
committed
Add: Nim Game
1 parent 2b64b21 commit 4e1f1e0

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

internal/leetcode/problems_status.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var problemStatus = map[int]bool{
9292
268: true,
9393
283: true,
9494
290: true,
95+
292: true,
9596
303: true,
9697
326: true,
9798
342: true,

problems/nim-game/nim_game.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
package nim_game
1+
package problem_292
2+
3+
func canWinNim(n int) bool {
4+
return n%4 != 0
5+
}

problems/nim-game/nim_game_test.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
package nim_game
1+
package problem_292
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected bool
8+
}
9+
10+
func TestCanWinNim(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 4,
14+
expected: false,
15+
},
16+
{
17+
input: 3,
18+
expected: true,
19+
},
20+
}
21+
for _, tc := range tests {
22+
output := canWinNim(tc.input)
23+
if output != tc.expected {
24+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)