Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursion solution in Clear category for Chess Knight by kdim
def chess_knight(start, moves):
if not moves: return []
if type(start) == str: start=[start]
c = []
for k in start:
a, b = ord(k[0]), int(k[1])
c += [ chr(a+i)+str(b+j) for i in (-2,2) for j in (-1,1) if 105>a+i>96 and 9>b+j>0]
c += [ chr(a+j)+str(b+i) for i in (-2,2) for j in (-1,1) if 105>a+j>96 and 9>b+i>0]
return sorted( set( c + chess_knight(c, moves-1) ) )
Jan. 12, 2021
Comments: