Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The shortest Knight's path solution in Uncategorized category for The Shortest Knight's Path by capback250
# migrated from python 2.7
COORDS = ((-1, -2), (1, -2), (-2, -1), (2, -1), (-2, 1), (2, 1), (-1, 2), (1, 2))
def checkio(coords):
start, goal = coords.split('-')
que = [start]
i = 0
while goal not in que:
que = rec(que)
i += 1
return i
def rec(que):
temp = []
for current in que:
for c in COORDS:
letter, number = chr(ord(current[0])+c[0]), int(current[1])+c[1]
if 'a' <= letter <= 'h' and number in range(1, 9):
nextJump = "{}{}".format(letter, number)
if nextJump not in temp:
temp.append(nextJump)
return temp
Feb. 2, 2016