Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Chess Knight by vvm70
def chess_knight(start, moves):
f = [start]
for _ in range(moves):
f = sorted(set(chr(ord(x) + i) + chr(ord(y) + j) for i in (-2, -1, 1, 2) for j in (-2, -1, 1, 2) for x, y in f\
if chr(ord(x) + i) in "abcdefgh" and (int(y) + j) in range(1, 9) and abs(i) != abs(j)) | set(f) - set([start]))
return f
if __name__ == '__main__':
print("Example:")
print(chess_knight('a1', 1))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert chess_knight('a1', 1) == ['b3', 'c2']
assert chess_knight('h8', 2) == ['d6', 'd8', 'e5', 'e7', 'f4', 'f7', 'f8', 'g5', 'g6', 'h4', 'h6', 'h8']
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 10, 2020