Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Square Spiral by jcg
import math
def coord(n) :
# coord :
#
#
#
# -2| 10 11 12 13
# -1| 9 2 3 14
# 0| 8 1 4
# 1| 7 6 5
# 2|______________
# -2 -1 0 1 2 x
#
# coord(1) -> (x=0, y=0)
# coord(14) -> (x=2, y=-1)
# each number k**2 + 1 <= n <= (k+1)**2 is on one of two sides
# of a square of side k.
#
# how to place the sequence s_k= [k**2 + 1..(k+1)**2] (length l = 2*k+1) ?
#
# if k is even,
# the sides are south then west, the directions are left, then up
# the first number of s_k is in the cell x = k//2, y = k//2
# the i-th number of s_k if 0<=i
May 30, 2014
Comments: