Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple recursion solution in Clear category for Chess Knight by martin_b
def chess_knight(p, l):
m = ((2, 1), (1, 2), (2, -1), (1, -2), (-2, 1), (-1, 2), (-2, -1), (-1, -2))
r = []
px, py = map(ord, p)
for dx, dy in m:
x, y = chr(px + dx), chr(py + dy)
if 'a' <= x <= 'h' and '1' <= y <= '8':
r.append(x + y)
if l > 1:
r += chess_knight(x + y, l - 1)
return sorted(set(r))
June 3, 2018
Comments: