OFFSET
1,9
COMMENTS
By convention we set a(1) = 0, because as 1 is a starting point of such spirals, it has no "inner neighbors" for itself.
This sequence is useful when constructing spiral-based sequences like A260643.
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..10001
Antti Karttunen, R6RS-Scheme program for computing this sequence
FORMULA
EXAMPLE
We arrange natural numbers as a counterclockwise spiral into the square grid in the following manner (here A stands for 10, B for 11 and C for 12). The first square corresponds with n, and the second square with the value of a(n):
05430
543C 50103
612B 61002
789A 70120
0789A0
-
For each n > 1, we look for the nearest horizontally or vertically adjacent neighbor of n towards the center that is not n-1, which will then be value of a(n) [e.g., it is 1 for 4, 6 and 8, while it is 2 for 9 and 11 and 3 for 12] unless no such additional neighbor exists, in which case a(n) = 0 (this occurs when n is one of the A033638, Quarter-squares plus 1).
PROG
(Scheme, with memoizing-macro definec, demonstrating the given recursive formula)
(definec (A265400 n) (cond ((<= n 3) 0) ((<= n 8) (- 1 (A000035 n))) ((= 1 (A240025 (- n 1))) 0) ((= 1 (A240025 (- n 2))) (A033638 (- (A000267 n) 4))) (else (+ 1 (A265400 (- n 1))))))
;; Another version which uses the variant A265410:
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 09 2015
STATUS
approved