(self)
| 2231 | return divmod(index, self.n) |
| 2232 | |
| 2233 | def _init_board(self): |
| 2234 | succs = self.succs |
| 2235 | del succs[:] |
| 2236 | m, n = self.m, self.n |
| 2237 | c2i = self.coords2index |
| 2238 | |
| 2239 | offsets = [( 1, 2), ( 2, 1), ( 2, -1), ( 1, -2), |
| 2240 | (-1, -2), (-2, -1), (-2, 1), (-1, 2)] |
| 2241 | rangen = range(n) |
| 2242 | for i in range(m): |
| 2243 | for j in rangen: |
| 2244 | s = [c2i(i+io, j+jo) for io, jo in offsets |
| 2245 | if 0 <= i+io < m and |
| 2246 | 0 <= j+jo < n] |
| 2247 | succs.append(s) |
| 2248 | |
| 2249 | # Generate solutions. |
| 2250 | def solve(self): |