Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #15 Dec 23 2024 14:53:44
%S 0,1,3,4,5,2,7,10,9,8,11,12,13,6,15,22,17,16,19,20,21,18,23,26,25,24,
%T 27,28,29,14,31,46,33,32,35,36,37,34,39,42,41,40,43,44,45,38,47,54,49,
%U 48,51,52,53,50,55,58,57,56,59,60,61,30,63,94,65,64,67,68,69
%N Permutation of the nonnegative integers such that sum_{k=0..n} (-1)^(a(k)+1)*a(k) is nonnegative and as small as possible, for n=0,1,....
%C Odd terms are added, even terms are subtracted. At each step, the next term is chosen among numbers which did not yet occur, as to minimize this sum.
%H M. F. Hasler, in reply to E. Angelini, <a href="https://web.archive.org/web/*/http://list.seqfan.eu/oldermail/seqfan/2014-November/013949.html">Minimizing Q</a>, SeqFan list, Nov 11 2014.
%F a(2n) = 2n+1 for n > 0; a(2^n-1) = 3*2^(n-1)-2 are particularly large "early bird" values (records of a(n)-n), a(2^n-3) = 2^(n-1)-2 are particularly small values (records of n-a(n), and also the values such that all subsequent terms are larger).
%o (PARI) a(n,a=0,Q=0,u=[])={for(n=1,n,print1(a",");u=setunion(u,Set(a));Q-=(-1)^a*a;forstep(k=Q%2,Q,2,setsearch(u,Q-k)&&next;a=Q-k;next(2));forstep(k=1,9e9,2,setsearch(u,k)&&next;a=k;next(2)))}
%Y Cf. A250090.
%K nonn
%O 0,3
%A _M. F. Hasler_ and _Eric Angelini_, Nov 11 2014