A352730 On a diagonally numbered square grid, with labels starting at 1, this is the number of steps that a (1,n) leaper makes before getting trapped when moving to the lowest available unvisited square, or -1 if it never gets trapped.
-1, 2402, -1, 1552, 287, 388, 417, 1593, 639, 1136, 1785, 3090, 2299, 2341, 1833, 4052, 2237, 3012, 3069, 6843, 5543, 3000, 5161, 11722, 6895, 3578, 8047, 19739, 9671, 4156, 8391, 21424, 15129, 4734, 8609, 32690, 19895, 5312, 10019, 42710, 21195, 5890, 12309, 53764, 34489, 6468, 19527, 55911, 23475
Offset: 1
Keywords
Programs
-
Python
n = 2 KM = [(n, 1), (1, n), (-1, n), (-n, 1), (-n, -1), (-1, -n), (1, -n), (n, -1)] def idx(loc): i, j = loc return (i + j - 1) * (i + j - 2) // 2 + j def next_move(loc, visited): i, j = loc moves = [(i + io, j + jo) for io, jo in KM if i + io > 0 and j + jo > 0] available = [m for m in moves if m not in visited] return min(available, default=None, key=lambda x: idx(x)) def aseq(): locs = [[], []] loc, s, turn, alst = [(1, 1), (1, 1)], {(1, 1)}, 0, [1] m = next_move(loc[turn], s) while m != None: loc[turn], s, turn, alst = m, s | {m}, 0, alst + [idx(m)] locs[turn] += [loc[turn]] m = next_move(loc[turn], s) if len(s) % 10000 == 0: print('{steps} moves in'.format(steps = len(s))) return alst print(aseq())
Comments