Skip to content

Instantly share code, notes, and snippets.

@betrue12
Last active October 24, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betrue12/b8c2c0cd479b8ae2b51cb8d5e0ff3b9e to your computer and use it in GitHub Desktop.
Save betrue12/b8c2c0cd479b8ae2b51cb8d5e0ff3b9e to your computer and use it in GitHub Desktop.
Strange Nim
X g
-------
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 1
11 0
12 1
13 0
14 1
15 0
16 1
17 0
18 1
19 0
20 2
21 1
22 0
23 2
24 1
25 0
26 2
27 1
28 0
29 2
30 3
31 1
32 0
33 2
34 3
35 1
36 0
37 2
38 3
39 1
40 4
41 0
42 2
43 3
44 1
45 4
46 0
47 2
48 3
49 1
50 5
51 4
52 0
53 2
54 3
55 1
56 5
57 4
58 0
59 2
60 6
61 3
62 1
63 5
64 4
65 0
66 2
67 6
68 3
69 1
70 7
71 5
72 4
73 0
74 2
75 6
76 3
77 1
78 7
79 5
80 8
81 4
82 0
83 2
84 6
85 3
86 1
87 7
88 5
89 8
90 9
91 4
92 0
93 2
94 6
95 3
96 1
97 7
98 5
99 8
100 10
101 9
102 4
103 0
104 2
105 6
106 3
107 1
108 7
109 5
110 11
111 8
112 10
113 9
114 4
115 0
116 2
117 6
118 3
119 1
120 12
121 7
122 5
123 11
124 8
125 10
126 9
127 4
128 0
129 2
130 13
131 6
132 3
133 1
134 12
135 7
136 5
137 11
138 8
139 10
140 14
141 9
142 4
143 0
144 2
145 13
146 6
147 3
148 1
149 12
150 15
A, K = gets.split.map(&:to_i)
grundy = [0]
(1..A).each do |i|
exist = Array.new(i+1)
(i-1).downto(i-i/K) do |j|
exist[grundy[j]] = true
end
(i+1).times do |j|
unless exist[j]
grundy[i] = j
break
end
end
end
(A+1).times do |i|
puts sprintf("%3d %2d", i, grundy[i])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment