Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Shortest Knight's Path by TovarischZhukov
nums="12345678"
chars="abcdefgh"
def checkio(cells):
start,end=cells.split("-")
start=(chars.find(start[0]),nums.find(start[1]))
end=(chars.find(end[0]), nums.find(end[1]))
matrix=[[2,1],[2,-1],[-2,1],[-2,-1],[1,2],[-1,2],[1,-2],[-1,-2]]
currents=[start]; checked=[];count=1
while 1:
new_currents=[]
for current in currents:
i=current[0]; j=current[1]
checked.append(current)
for k in matrix:
pos=i+k[0],j+k[1]
if 0<=pos[0]<8 and 0<=pos[1]<8 and pos not in checked:
new_currents.append(pos)
if end==pos: return count
currents=new_currents
count+=1
return count
Jan. 26, 2016