Skip to content

Instantly share code, notes, and snippets.

@mahiuchun
Created April 25, 2013 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahiuchun/5458313 to your computer and use it in GitHub Desktop.
Save mahiuchun/5458313 to your computer and use it in GitHub Desktop.
dist = [0, 0, 0, 0]
isi = [-26, -10, 10, 26]
yn = [39, 21, -13, -29, -15, -19]
for i in range(0, 6):
dist2 = dist[:]
for j in range(0, 4):
lsb = j % 2
msb = j // 2
x0 = 0
if msb == 1:
x0 = 29
else:
x0 = -29
ix = 0
ix1 = 2*lsb
ix2 = 2*lsb+1
dd1 = (yn[i] - (x0 + isi[ix1])) ** 2 + dist[ix1]
dd2 = (yn[i] - (x0 + isi[ix2])) ** 2 + dist[ix2]
if dd1 < dd2:
ix = ix1
dist2[j] = dd1
else:
ix = ix2
dist2[j] = dd2
print(x0 + isi[ix], ix, str(dist2[j])+"\t", end="")
dist = dist2[:]
print(end="\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment