Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #121 Jan 26 2025 23:41:22
%S 0,1,2,-2,-1,3,4,5,-4,-3,6,7,8,-8,-7,-6,-5,-9,-10,-11,-12,13,9,10,11,
%T 12,-13,-14,-15,-16,-17,-18,18,14,15,16,17,-19,-20,-21,-22,-23,-24,25,
%U 21,20,19,23,22,26,27,28,24,-25,-26,-27,-28,-29,-30,-31,-32,32
%N a(0) = 0; thereafter a(n) is the least integer (in absolute value) not yet in the sequence such that the absolute difference of a(n-1) and a(n) is a square; in case of a tie, preference is given to the positive value.
%C Conjecture: Every integer (positive or negative) appears in this sequence.
%C Conjecture: For n > 16, |a(n)| is within sqrt(n/2) of floor(n/2). See A379071. - _N. J. A. Sloane_, Dec 29 2024 [Corrected by _Paolo Xausa_, Jan 21 2025]
%H N. J. A. Sloane, <a href="/A377091/b377091.txt">Table of n, a(n) for n = 0..20000</a> [First 10000 terms from Rémy Sigrist]
%H M. F. Hasler, <a href="/A377091/a377091_2.html">Interactive spiral graph representation of the first n terms</a>, Jan 18 2025.
%H Kerry Mitchell, <a href="/A377091/a377091_2.jpg">Spiral graph representation of first 31 terms</a>
%H Kerry Mitchell, <a href="/A377091/a377091_3.jpg">Colored spiral graph representation of first 100 terms</a>
%H Chris Scussel, <a href="/A377091/a377091.pdf">Spiral graph representation of 5000 terms</a>
%H Rémy Sigrist, <a href="/A377091/a377091.png">Scatterplot of the first 10000 terms of the partial sums</a>
%H Rémy Sigrist, <a href="/A377091/a377091_1.png">Christmas card based on graph of the partial sums</a> [Rotate graph by 90 degs, add color and decorations]
%H Rémy Sigrist, <a href="/A377091/a377091.gp.txt">PARI program</a>
%H N. J. A. Sloane, <a href="/A377091/a377091.txt">Table of n, a(n) for n = 0..250000</a>
%H N. J. A. Sloane, <a href="/A377091/a377091_1.jpg">Spiral graph representation of first 28 terms</a> [Hand-drawn]
%e The initial terms are:
%e n a(n) |a(n)-a(n-1)|
%e -- ---- -------------
%e 0 0 N/A
%e 1 1 1^2
%e 2 2 1^2
%e 3 -2 2^2
%e 4 -1 1^2
%e 5 3 2^2
%e 6 4 1^2
%e 7 5 1^2
%e 8 -4 3^2
%e 9 -3 1^2
%e 10 6 3^2
%e 11 7 1^2
%e 12 8 1^2
%e 13 -8 4^2
%e 14 -7 1^2
%p h := proc(b, a, i) option remember; ifelse(issqr(abs(a[-1] - i)) and not is(i in a), ifelse(b < nops(a) + 1, a, h(b, [op(a), i], 1)), h(b, a, ifelse(i < 0, 1 - i, -i))) end:
%p a_list := length -> h(length, [0], 1): a_list(62); # _Peter Luschny_, Jan 20 2025
%t A377091list[nmax_] := Module[{s, a = 0, an, u = 1}, s[_] := False; s[0] = True; Join[{0}, Table[a = (While[s[u] && s[-u], u++]; an = u; While[s[an] || !IntegerQ[Sqrt[Abs[a - an]]], an = Boole[an < 0] - an]; s[an] = True; an), nmax]]];
%t A377091list[100] (* _Paolo Xausa_, Jan 20 2025 *)
%o (PARI) \\ See Links section.
%o (PARI) A377091_upto(n,S=[])={vector(n+1, k, S=setunion(S, [n=if(k>1, k=1; while(setsearch(S,k) || !issquare(abs(n-k)), k=(k<0)-k); k)]); n)} \\ _M. F. Hasler_, Jan 18 2025
%o (Python)
%o from math import isqrt
%o from itertools import count, islice
%o def cond(n): return isqrt(n)**2 == n
%o def agen(): # generator of terms
%o an, aset, m = 0, {0}, 1
%o for n in count(0):
%o yield an
%o an = next(s for k in count(m) for s in [k, -k] if s not in aset and cond(abs(an-s)))
%o aset.add(an)
%o while m in aset and -m in aset: m += 1
%o print(list(islice(agen(), 62))) # _Michael S. Branicky_, Dec 25 2024
%o (Python)
%o from math import sqrt
%o def a_list(b: int, a: list[int] = [0], i: int = 1) -> list[int]:
%o if sqrt(abs(a[-1] - i)).is_integer() and not (i in a):
%o a += [i]
%o if b < len(a):
%o return a
%o else:
%o return a_list(b, a)
%o else:
%o return a_list(b, a, int(i < 0) - i)
%o print(a_list(40)) # _Peter Luschny_, Jan 20 2025
%o (JavaScript)
%o A377091 = [0]; A377091.least_unused = 1;
%o function a(n){
%o for(let i = A377091.length-1; i < n; ++i) {
%o let k = A377091.least_unused;
%o while(!Number.isInteger(Math.sqrt(Math.abs(A377091[i] - k)))
%o || A377091.indexOf(k) > 0) k = (k<0)-k;
%o A377091.push(k);
%o if (k == A377091.least_unused) {
%o do k = (k<0)-k; while ( A377091.indexOf( k ) > 0 );
%o A377091.least_unused = k;
%o } };
%o return A377091[n];
%o } // _M. F. Hasler_, Jan 26 2025
%Y This sequence is a variant of A277616 allowing negative values.
%Y Cf. A277617, A277618, A377090, A377092.
%Y A large number of sequences have been derived from the present sequence in the hope (so far unfulfilled) of finding a formula or recurrence: see A379057-A379078, A379786-A379798, A379802, A379803, A379804, A379880, A380223, A380224, A380225.
%K sign,look,nice,changed
%O 0,3
%A _Rémy Sigrist_, Oct 16 2024