Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for The Shortest Knight's Path by panaro32
def checkio(s):
m = ((1,2),(2,1),(2,-1),(1,-2),(-1,-2),(-2,-1),(-2,1),(-1,2))
f = lambda p: [(p[0]+x,p[1]+y) for x,y in m if 0<=p[0]+x<8 and 0<=p[1]+y<8]
a,b = map(lambda x: (ord(x[0])-ord('a'),int(x[1])-1),s.split('-'))
l,k = [a],0
while not b in l: l,k = sum(map(f,l),[]),k+1
return k
if __name__ == "__main__":
assert checkio("b1-d5") == 2, "1st example"
assert checkio("a6-b8") == 1, "2nd example"
assert checkio("h1-g2") == 4, "3rd example"
assert checkio("h8-d7") == 3, "4th example"
assert checkio("a1-h8") == 6, "5th example"
June 19, 2014