Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
1.88400006294e-06s per call solution in Speedy category for The Shortest Knight's Path by ArchTauruS
# 1.88400006294e-06 s per call
knight_moves = [[0, 3, 2, 3, 2, 3, 4, 5],
[3, 2, 1, 2, 3, 4, 3, 4],
[2, 1, 4, 3, 2, 3, 4, 5],
[3, 2, 3, 2, 3, 4, 3, 4],
[2, 3, 2, 3, 4, 3, 4, 5],
[3, 4, 3, 4, 3, 4, 5, 4],
[4, 3, 4, 3, 4, 5, 4, 5],
[5, 4, 5, 4, 5, 4, 5, 6]] # table of knight moves
def checkio(move):
if move in ["h1-g2", "g2-h1", "h8-g7", "g7-h8",
"a1-b2", "b2-a1", "a8-b7", "b7-a8"]: # exceptions
return 4
x1, y1, x2, y2 = (ord(move[0]), "12345678".index(move[1]),
ord(move[3]), "12345678".index(move[4]))
return knight_moves[abs(y1 - y2)][abs(x1 - x2)]
Sept. 30, 2014
Comments: