OFFSET
0,3
COMMENTS
Conjecture: Every integer (positive or negative) appears in this sequence.
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]
LINKS
N. J. A. Sloane, Table of n, a(n) for n = 0..20000 [First 10000 terms from Rémy Sigrist]
M. F. Hasler, Interactive spiral graph representation of the first n terms, Jan 18 2025.
Kerry Mitchell, Spiral graph representation of first 31 terms
Kerry Mitchell, Colored spiral graph representation of first 100 terms
Chris Scussel, Spiral graph representation of 5000 terms
Rémy Sigrist, Scatterplot of the first 10000 terms of the partial sums
Rémy Sigrist, Christmas card based on graph of the partial sums [Rotate graph by 90 degs, add color and decorations]
Rémy Sigrist, PARI program
N. J. A. Sloane, Table of n, a(n) for n = 0..250000
N. J. A. Sloane, Spiral graph representation of first 28 terms [Hand-drawn]
EXAMPLE
The initial terms are:
n a(n) |a(n)-a(n-1)|
-- ---- -------------
0 0 N/A
1 1 1^2
2 2 1^2
3 -2 2^2
4 -1 1^2
5 3 2^2
6 4 1^2
7 5 1^2
8 -4 3^2
9 -3 1^2
10 6 3^2
11 7 1^2
12 8 1^2
13 -8 4^2
14 -7 1^2
MAPLE
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:
a_list := length -> h(length, [0], 1): a_list(62); # Peter Luschny, Jan 20 2025
MATHEMATICA
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]]];
A377091list[100] (* Paolo Xausa, Jan 20 2025 *)
PROG
(PARI) \\ See Links section.
(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
(Python)
from math import isqrt
from itertools import count, islice
def cond(n): return isqrt(n)**2 == n
def agen(): # generator of terms
an, aset, m = 0, {0}, 1
for n in count(0):
yield an
an = next(s for k in count(m) for s in [k, -k] if s not in aset and cond(abs(an-s)))
aset.add(an)
while m in aset and -m in aset: m += 1
print(list(islice(agen(), 62))) # Michael S. Branicky, Dec 25 2024
(Python)
from math import sqrt
def a_list(b: int, a: list[int] = [0], i: int = 1) -> list[int]:
if sqrt(abs(a[-1] - i)).is_integer() and not (i in a):
a += [i]
if b < len(a):
return a
else:
return a_list(b, a)
else:
return a_list(b, a, int(i < 0) - i)
print(a_list(40)) # Peter Luschny, Jan 20 2025
(JavaScript)
function a(n){
for(let i = A377091.length-1; i < n; ++i) {
let k = A377091.least_unused;
while(!Number.isInteger(Math.sqrt(Math.abs(A377091[i] - k)))
|| A377091.indexOf(k) > 0) k = (k<0)-k;
A377091.push(k);
if (k == A377091.least_unused) {
do k = (k<0)-k; while ( A377091.indexOf( k ) > 0 );
A377091.least_unused = k;
} };
return A377091[n];
} // M. F. Hasler, Jan 26 2025
CROSSREFS
This sequence is a variant of A277616 allowing negative values.
KEYWORD
AUTHOR
Rémy Sigrist, Oct 16 2024
STATUS
approved