%I #18 Mar 03 2023 13:51:07
%S 0,1,0,2,3,3,1,4,3,5,5,6,8,7,4,8,9,9,7,10,10,11,10,12,10,13,14,14,17,
%T 15,11,16,15,17,17,18,20,19,16,20,20,21,20,22,23,23,21,24,26,25,22,26,
%U 25,27,27,28,25,29,31,30,34,31,26,32,33,33,31,34,34,35,34,36,34,37,38,38,41,39,35,40,40,41,40,42,43,43,41,44,43,45,45,46,48
%N Running sum of Noergaard's "infinity sequence" A004718.
%C If s(n) is A004718, then a(2n) = n - s(n) and a(2n+1) = n+1.
%H Alois P. Heinz, <a href="/A274604/b274604.txt">Table of n, a(n) for n = 0..10000</a>
%H Yu Hin (Gary) Au, Christopher Drexler-Lemire & Jeffrey Shallit, <a href="https://doi.org/10.1080/17459737.2017.1299807">Notes and note pairs in Nørgård's infinity series</a>, Journal of Mathematics and Music, Volume 11, 2017, Issue 1, pages 1-19.
%p b:= proc(n) option remember; local r; `if`(n=0, 0,
%p `if`(irem(n, 2, 'r')=0, -b(r), b(r)+1))
%p end:
%p a:= proc(n) a(n):= b(n)+`if`(n=0, 0, a(n-1)) end:
%p seq(a(n), n=0..100); # _Alois P. Heinz_, Jun 30 2016
%t b[n_] := b[n] = Module[{q, r}, If[n == 0, 0, {q, r} = QuotientRemainder[n, 2]; If[r == 0, -b[q], b[q] + 1]]];
%t a[n_] := b[n] + If[n == 0, 0, a[n - 1]];
%t a /@ Range[0, 100] (* _Jean-François Alcover_, Nov 24 2020, after _Alois P. Heinz_ *)
%o (Python)
%o from itertools import groupby
%o def A274604(n):
%o if n&1: return (n>>1)+1
%o c = 0
%o for k, g in groupby(bin(m:=n>>1)[2:]):
%o c = c+len(list(g)) if k == '1' else (-c if len(list(g))&1 else c)
%o return m-c # _Chai Wah Wu_, Mar 03 2023
%Y Cf. A004718.
%K nonn
%O 0,4
%A _Jeffrey Shallit_, Jun 30 2016