Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10-liner: easy recursive solution in Creative category for Chess Knight by przemyslaw.daniel
STEPS = (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1), (-2, 1), (-1, 2)
VALID = {x+y for x in 'abcdefgh' for y in '12345678'}
def chess_knight(start, moves, root=True):
if start not in VALID: return []
if not moves: return [start]
x, y = map(ord, start)
result = sum([chess_knight(chr(x+i)+chr(y+j), moves-1, False)
for i, j in STEPS], [start]*(not root))
return sorted(set(result))
May 21, 2018