%I #10 Oct 28 2024 16:24:26
%S 0,1,-2,-3,-5,-8,-6,-11,-13,-21,-16,9,-42,-24,-25,-27,-34,-35,-46,10,
%T 2,90,42,31,26,11,30,18,58,41,20,86,43,60,45,103,48,54,105,83,-48,
%U -151,-155,-59,-87,-79,-146,106,-157,-109,-218,-208,-88,-45,-99,-131,27
%N Infinite sequence of integers a(1), a(2), ... such that for any n > 0, a(n) is as small as possible (in absolute value) and the means of consecutive terms are all distinct; in case of a tie, preference is given to the positive value.
%C This sequence is a variant of A377351 allowing negative values.
%C All terms are distinct.
%H Rémy Sigrist, <a href="/A377388/b377388.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A377388/a377388.txt">C++ program</a>
%e The first terms, alongside the means of consecutive terms ending with a(n), are:
%e n a(n) Corresponding means
%e - ---- -----------------------------------------
%e 1 0 0
%e 2 1 1/2, 1
%e 3 -2 -1/3, -1/2, -2
%e 4 -3 -1, -4/3, -5/2, -3
%e 5 -5 -9/5, -9/4, -10/3, -4, -5
%e 6 -8 -17/6, -17/5, -9/2, -16/3, -13/2, -8
%e 7 -6 -23/7, -23/6, -24/5, -11/2, -19/3, -7, -6
%o (C++) // See Links section.
%o (Python)
%o from fractions import Fraction
%o from itertools import count, islice
%o def A377388gen(): # generator of terms
%o alst, means_seen = [0], {0}
%o while True:
%o yield alst[-1]
%o for i in count(1):
%o failed = True
%o for k in [i, -i]:
%o if k in means_seen: continue
%o mk, failed, sk = {k}, False, k
%o for j in range(1, len(alst)+1):
%o sk += alst[-j]
%o m = Fraction(sk, j+1)
%o if m in means_seen or m in mk: failed = True; break
%o mk.add(m)
%o if not failed:
%o means_seen |= mk
%o alst.append(k)
%o break
%o if not failed: break
%o print(list(islice(A377388gen(), 60))) # _Michael S. Branicky_, Oct 27 2024, Oct 28 2024
%Y Cf. A377351, A377389.
%K sign
%O 1,3
%A _Rémy Sigrist_, Oct 27 2024