Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First - walk the line solution in Clear category for Square Spiral by Tinus_Trotyl
def find_distance(a, b):
def coords(n):
j = r = x = y = 0
while j < n:
r += 1
for dx, dy in (0, 1), (1, 0), (0, -1), (-1, 0):
while j < n and dx * x + dy * y < r :
j, x, y = j + 1, x + dx, y + dy
return x, y
xa, ya = coords(a - 1)
xb, yb = coords(b - 1)
return abs(xa - xb) + abs(ya - yb)
March 16, 2019
Comments: