cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A232115 a(n) is the Manhattan distance between n and n(n+1)/2 in a square spiral of positive integers with 1 at the center.

This page as a plain text file.
%I A232115 #17 Jul 04 2025 14:10:09
%S A232115 0,1,3,4,2,3,5,6,4,5,9,6,6,7,11,8,8,15,9,10,10,13,11,12,22,11,15,18,
%T A232115 12,15,17,22,12,21,25,10,26,21,19,18,24,27,15,34,24,21,31,20,28,21,31,
%U A232115 24,28,41,19,36,36,23,35,26,38,23,41,36,28,53,29,38,40,31,39
%N A232115 a(n) is the Manhattan distance between n and n(n+1)/2 in a square spiral of positive integers with 1 at the center.
%C A232115 Spiral begins:
%C A232115 .
%C A232115   49  26--27--28--29--30--31
%C A232115    |   |                   |
%C A232115   48  25  10--11--12--13  32
%C A232115    |   |   |           |   |
%C A232115   47  24   9   2---3  14  33
%C A232115    |   |   |   |   |   |   |
%C A232115   46  23   8   1   4  15  34
%C A232115    |   |   |       |   |   |
%C A232115   45  22   7---6---5  16  35
%C A232115    |   |               |   |
%C A232115   44  21--20--19--18--17  36
%C A232115    |                       |
%C A232115   43--42--41--40--39--38--37
%C A232115 .
%C A232115 Numbers n such that a(n)*2=n: 2, 6, 10, 12, 14, 16, 20, 24, 30, 80, 192, 198, 350, 524, 536, 548, 552, 560, 564, 576, 588, 594, 606, 618, 630, 1380, 1900, 4446, ...
%o A232115 (Python)
%o A232115 import math
%o A232115 def get_x_y(n):
%o A232115   sr = math.isqrt(n-1)
%o A232115   sr = sr-1+(sr&1)
%o A232115   rm = n-sr*sr
%o A232115   d = (sr+1)//2
%o A232115   if rm<=sr+1:
%o A232115      return -d+rm,d
%o A232115   if rm<=sr*2+2:
%o A232115      return d,d-(rm-(sr+1))
%o A232115   if rm<=sr*3+3:
%o A232115      return d-(rm-(sr*2+2)),-d
%o A232115   return -d,-d+rm-(sr*3+3)
%o A232115 for n in range(1,333):
%o A232115   x0,y0 = get_x_y(n)
%o A232115   x1,y1 = get_x_y(n*(n+1)//2)
%o A232115   print(abs(x1-x0)+abs(y1-y0), end=', ')
%Y A232115 Cf. A000217, A214526, A232113, A232114.
%K A232115 nonn
%O A232115 1,3
%A A232115 _Alex Ratushnyak_, Nov 19 2013