Skip to content

Instantly share code, notes, and snippets.

@tomprince
Created September 9, 2016 05:24
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 tomprince/967cbe6193dfae6d0a10bcb30d9533ad to your computer and use it in GitHub Desktop.
Save tomprince/967cbe6193dfae6d0a10bcb30d9533ad to your computer and use it in GitHub Desktop.
from math import sqrt, ceil
def shell(n):
a = int(ceil(sqrt(n)))
if a % 2 == 0:
a += 1
c = a - 1
d = c / 2
return d
def f(n):
if n == 1:
return (0, 0)
d = shell(n)
a = 2*d + 1
c = 2*d
b = n - (a-2)**2
bm = (b-1) % c + 1
#print d, b, int((b-1)/c)
return [
(d, bm-d),
(d-bm, d),
(-d, d-bm),
(bm-d, -d),
][int((b-1)/c)]
for n in range(25):
print f(n+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment