OFFSET
0,3
COMMENTS
The sequence is an alternative solution to the riddle described in the comments of A304584 without the restriction of x and d to nonnegative numbers.
LINKS
Rainer Rosenthal, Table of n, a(n) for n = 0..10000
EXAMPLE
d:
3 | 16 28
| / \ \
2 | 17 7 15 27
| / / \ \ \
1 | 18 8 2 6 14 26
| / / / \ \ \ \
0 | 19 9 3 0---1 5 13 25
| \ \ \ --> --> -->
-1 | 20 10 4 12 24
| \ \ / /
-2 | 21 11 23
| \ /
-3 | 22
__________________________________
x: -3 -2 -1 0 1 2 3 4
.
a(10) = -1 + 10*(-1) = -11 because the 10th position in the spiral corresponds to x = -1 and d = -1,
a(15) = 1 + 15*2 = 31 because the 15th position in the spiral corresponds to x = 1 and d = 2,
a(25) = 4 + 25*0 = 4 because the 25th position in the spiral corresponds to x = 4 and d = 0.
MAPLE
n2left := proc(n)local w, k; return floor(sqrt((n-1)/2)); end:pos2pH:=proc(n)local k, q, Q, e, E, sp; k:=n2left(n); q:=2*k^2+1; Q:=2*(k+1)^2+1; e:=n-q; E:=Q-n; if n<2 then return[n, 0]; fi; if e<=k then return[-k+e, -e]; elif e<2*k then return[-k+e, -2*k+e]; elif E<=k+1 then return[-(k+1)+E, E]; else return[E-(k+1), 2*(k+1)-E]; fi; end:WhereFlea:=proc(n) local x, d, pair; pair:=pos2pH(n); x:=pair[1]; d:=pair[2]; return x+d*n; end: seq(WhereFlea(n), n=0..62); # Rainer Rosenthal, May 28 2018
PROG
(Sage)
def a(n):
if n<2: return n
k = isqrt((n-1)/2)
e = n-k*(2*k+1)-1
x = e if e<k else k*(2*k+3)-n+2
d = abs(x)-k if e<k else k+1-abs(x)
return x + d*n
print([a(n) for n in range(63)]) # Peter Luschny, May 29 2018
CROSSREFS
KEYWORD
sign,look
AUTHOR
Hugo Pfoertner, May 16 2018
EXTENSIONS
a(1) corrected by Rainer Rosenthal, May 28 2018
STATUS
approved