Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #10 Dec 23 2024 14:53:44
%S 1,0,3,2,5,6,7,4,9,12,11,10,13,14,15,8,17,24,19,18,21,22,23,20,25,28,
%T 27,26,29,30,31,16,33,48,35,34,37,38,39,36,41,44,43,42,45,46,47,40,49,
%U 56,51,50,53,54,55,52,57,60,59,58,61,62,63,32,65,96,67,66,69,70,71,68,73,76,75,74,77,78,79,72,81,88,83,82,85,86,87,84,89,92,91
%N a(0)=1; for n>0, a(n) is the number not yet used which yields the smallest possible positive sum_{k=0..n} (-1)^(a(k)+1)*a(k).
%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 E. Angelini, <a href="https://web.archive.org/web/*/http://list.seqfan.eu/oldermail/seqfan/2014-November/013948.html">Minimizing Q</a>, SeqFan list, Nov 11 2014.
%o (PARI) A250090(n=100,a=1,Q=0,u=[])={for(n=1,n,print1(a",");u=setunion(u,Set(a));Q-=(-1)^a*a;forstep(k=2-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)));a} \\ returns a(n) and prints out a(k) for 0<=k<n.
%Y Cf. A250072.
%K nonn
%O 0,3
%A _Eric Angelini_ and _M. F. Hasler_, Nov 11 2014