login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A140358
Smallest nonnegative integer k such that n = +-1+-2+-...+-k for some choice of +'s and -'s.
3
0, 1, 3, 2, 3, 5, 3, 5, 4, 5, 4, 5, 7, 5, 7, 5, 7, 6, 7, 6, 7, 6, 7, 9, 7, 9, 7, 9, 7, 9, 8, 9, 8, 9, 8, 9, 8, 9, 11, 9, 11, 9, 11, 9, 11, 9, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 13, 11, 13, 11, 13, 11, 13, 11, 13, 11, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 15, 13, 15, 13
OFFSET
0,3
FORMULA
Conjecture when n is greater than 0. Choose k so that t(k)<=n<t(k+1) where t(n) is the n-th triangular number t(n)=n(n+1)/2. If n=t(k), a(n)=k, otherwise if k is odd then a(n)=k+2 if n-t(k) is odd, a(n)=k+1 if n-t(k) is even, else if k is even than a(n)=k+1 if n-t(k) is odd, a(n)=k+3 if n-t(k) is even. (This has been verified for n up to 100.)
a(n) = a(-n) for all n in Z. - Seiichi Manyama, Aug 18 2020
Let k be the least integer such that t(k) >= n. If t(k) and n have the same parity then a(n) = k. Otherwise a(n) is equal to the least odd integer greater than k. - Rishi Advani, Jan 24 2021
EXAMPLE
From Seiichi Manyama, Aug 18 2020: (Start)
Illustration of initial terms:
0 = 0 (empty sum).
1 = 1.
2 = 1 - 2 + 3.
3 = 1 + 2.
4 = -1 + 2 + 3.
5 = 1 + 2 + 3 + 4 - 5.
6 = 1 + 2 + 3.
7 = 1 + 2 + 3 - 4 + 5.
8 = -1 + 2 + 3 + 4.
9 = 1 + 2 - 3 + 4 + 5.
10 = 1 + 2 + 3 + 4.
... (End)
MAPLE
b:= proc(n, i) option remember;
(n=0 and i=0) or n<=i*(i+1)/2 and (b(abs(n-i), i-1) or b(n+i, i-1))
end:
a:= proc(n) local k;
for k from 0 while not b(n, k) do od; k
end:
seq(a(n), n=0..100); # Alois P. Heinz, Oct 19 2011
MATHEMATICA
b[n_, i_] := b[n, i] = (n==0 && i==0) || Abs[n] <= i(i+1)/2 && (b[n-i, i-1] || b[n+i, i-1]);
a[n_] := Module[{k}, For[k = 0, !b[n, k], k++]; k];
a /@ Range[0, 100] (* Jean-François Alcover, Nov 15 2020, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn,look
AUTHOR
John W. Layman, Jun 23 2008
EXTENSIONS
a(0)=3 prepended by Seiichi Manyama, Aug 17 2020
Edited and a(0)=0 from Alois P. Heinz, Aug 18 2020
STATUS
approved