login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A333596 a(0) = 0; for n > 0, a(n) = a(n-1) + (number of 1's and 3's in base-4 representation of n) - (number of 0's and 2's in base-4 representation of n). 1

%I #77 Jun 25 2021 23:17:10

%S 0,1,0,1,1,3,3,5,3,3,1,1,1,3,3,5,4,5,4,5,6,9,10,13,12,13,12,13,14,17,

%T 18,21,18,17,14,13,12,13,12,13,10,9,6,5,4,5,4,5,4,5,4,5,6,9,10,13,12,

%U 13,12,13,14,17,18,21,19,19,17,17,17,19,19,21,19,19

%N a(0) = 0; for n > 0, a(n) = a(n-1) + (number of 1's and 3's in base-4 representation of n) - (number of 0's and 2's in base-4 representation of n).

%C Local maxima values minus 1 are divisible by 4.

%C For a digit-wise recurrence, it's convenient to sum n terms so b(n) = a(n-1) = Sum_{i=0..n-1} A334841(i). Then b(4n+r) = 4*b(n) + r*A334841(n) + (1 if r even), for 0 <= r <= 3 and 4n+r >= 1. This is 4 copies of terms 0..n-1 and r copies of the following n. The new lowest digits cancel when r is odd, or net +1 when r is even. Repeatedly expanding gives the PARI code below. - _Kevin Ryde_, Jun 02 2020

%e n in #odd #even

%e n base 4 digits - digits + a(n-1) = a(n)

%e = ====== ===============================

%e 0 0 0 - 0

%e 1 1 1 - 0 + 0 = 1

%e 2 2 0 - 1 + 1 = 0

%e 3 3 1 - 0 + 0 = 1

%e 4 10 1 - 1 + 1 = 1

%e 5 11 2 - 0 + 1 = 3

%e 6 12 1 - 1 + 3 = 3

%e 7 13 2 - 0 + 3 = 5

%p a:= proc(n) option remember; `if`(n=0, 0, a(n-1) +add(

%p `if`(i in [1, 3], 1, -1), i=convert(n, base, 4)))

%p end:

%p seq(a(n), n=0..80); # _Alois P. Heinz_, May 30 2020

%t f[n_] := Total[(-1)^(r = Range[0, 3]) * DigitCount[n, 4, r]]; a[0] = 0; a[n_] := a[n] = a[n - 1] - f[n]; Array[a, 100, 0] (* _Amiram Eldar_, Apr 24 2020 *)

%o (R)

%o qnary = function(n, e, q){

%o e = floor(n/4)

%o q = n%%4

%o if(n == 0 ){return(0)}

%o if(e == 0){return(q)}

%o else{return(c(qnary(e), (q)))}

%o }

%o m = 400

%o s = seq(2,m)

%o v = c(0)

%o for(i in s){

%o x = qnary(i-1)

%o x[which(x%%2!=0)] = 1

%o x[which(x%%2==0)] = -1

%o v[i] = sum(x,v[i-1])

%o }

%o (Python)

%o import numpy as np

%o def qnary(n):

%o e = n//4

%o q = n%4

%o if n == 0 : return 0

%o if e == 0 : return q

%o if e != 0 : return np.append(qnary(e), q)

%o m = 400

%o v = [0]

%o for i in range(1,m+1) :

%o t = np.array(qnary(i))

%o t[t%2 != 0] = 1

%o t[t%2 == 0] = -1

%o v = np.append(v, np.sum([np.sum(t), v[i-1]]))

%o (PARI) a(n) = my(v=digits(n+1,4),s=0); for(i=1,#v, my(t=v[i]); v[i]=t*s+!(t%2); s-=(-1)^t); fromdigits(v,4); \\ _Kevin Ryde_, May 30 2020

%o (PARI) b(n)=my(d=digits(n,4)); -sum(i=1,#d,(-1)^d[i])

%o first(n)=my(s); concat(0,vector(n,k,s+=b(k))) \\ _Charles R Greathouse IV_, Jul 04 2020

%o (Python)

%o from itertools import accumulate

%o def A334841(n):

%o return 2*bin(n)[-1:1:-2].count('1')-(len(bin(n))-1)//2 if n > 0 else 0

%o A333596_list = list(accumulate(A334841(n) for n in range(10000))) # _Chai Wah Wu_, Sep 03 2020

%Y Cf. A053737, A010065, A037863, A268289, A007090, A231664, A301336, A334841.

%K nonn,base,easy

%O 0,6

%A _Alexander Van Plantinga_, Mar 27 2020

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 19 21:09 EDT 2024. Contains 371798 sequences. (Running on oeis4.)