Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
*map & *starmap solution in Creative category for Chess Knight by flpo
from itertools import starmap
MOVES = ((-1, 2), (-2, 1), (-1, -2), (-2, -1), (1, 2), (2, 1), (1, -2), (2, -1))
CHESS = {(r, c) for r in range(97, 105) for c in range(49, 57)}
ords2str = lambda ords: list(sorted(chr(x) + chr(y) for x, y in ords))
next_pos = lambda r, c: {(r + x, c + y) for x, y in MOVES} & CHESS
def chess_knight(p, h):
next1 = next_pos(*map(ord, p))
return ords2str(next1 if h == 1 else next1.union(*starmap(next_pos, next1)))
April 28, 2018