Skip to content

Instantly share code, notes, and snippets.

@barneygale
Created September 6, 2012 18:45
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 barneygale/3659371 to your computer and use it in GitHub Desktop.
Save barneygale/3659371 to your computer and use it in GitHub Desktop.
def steps():
a = 1
dx = 0
dy = 0
x = 0
y = 0
while True:
a += 1
dx = ((1+a) & 1) - (2 if (a % 4) == 0 else 0)
dy = (a & 1) - (2 if (a % 4) == 1 else 0)
for i in range(a >> 1):
x += dx
y += dy
yield x, y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment