cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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).

This page as a plain text file.
%I A333596 #77 Jun 25 2021 23:17:10
%S A333596 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 A333596 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 A333596 13,12,13,14,17,18,21,19,19,17,17,17,19,19,21,19,19
%N 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).
%C A333596 Local maxima values minus 1 are divisible by 4.
%C A333596 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 A333596       n in    #odd    #even
%e A333596   n  base 4  digits - digits + a(n-1) = a(n)
%e A333596   =  ======  ===============================
%e A333596   0    0        0   -                     0
%e A333596   1    1        1   -    0   +    0   =   1
%e A333596   2    2        0   -    1   +    1   =   0
%e A333596   3    3        1   -    0   +    0   =   1
%e A333596   4   10        1   -    1   +    1   =   1
%e A333596   5   11        2   -    0   +    1   =   3
%e A333596   6   12        1   -    1   +    3   =   3
%e A333596   7   13        2   -    0   +    3   =   5
%p A333596 a:= proc(n) option remember; `if`(n=0, 0, a(n-1) +add(
%p A333596      `if`(i in [1, 3], 1, -1), i=convert(n, base, 4)))
%p A333596     end:
%p A333596 seq(a(n), n=0..80);  # _Alois P. Heinz_, May 30 2020
%t A333596 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 A333596 (R)
%o A333596 qnary = function(n, e, q){
%o A333596   e = floor(n/4)
%o A333596   q = n%%4
%o A333596   if(n == 0 ){return(0)}
%o A333596   if(e == 0){return(q)}
%o A333596   else{return(c(qnary(e), (q)))}
%o A333596 }
%o A333596 m = 400
%o A333596 s = seq(2,m)
%o A333596 v = c(0)
%o A333596 for(i in s){
%o A333596   x = qnary(i-1)
%o A333596   x[which(x%%2!=0)] = 1
%o A333596   x[which(x%%2==0)] = -1
%o A333596   v[i] = sum(x,v[i-1])
%o A333596 }
%o A333596 (Python)
%o A333596 import numpy as np
%o A333596 def qnary(n):
%o A333596     e = n//4
%o A333596     q = n%4
%o A333596     if n == 0 : return 0
%o A333596     if e == 0 : return q
%o A333596     if e != 0 : return np.append(qnary(e), q)
%o A333596 m = 400
%o A333596 v = [0]
%o A333596 for i in range(1,m+1) :
%o A333596     t = np.array(qnary(i))
%o A333596     t[t%2 != 0] = 1
%o A333596     t[t%2 == 0] = -1
%o A333596     v = np.append(v, np.sum([np.sum(t), v[i-1]]))
%o A333596 (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 A333596 (PARI) b(n)=my(d=digits(n,4)); -sum(i=1,#d,(-1)^d[i])
%o A333596 first(n)=my(s); concat(0,vector(n,k,s+=b(k))) \\ _Charles R Greathouse IV_, Jul 04 2020
%o A333596 (Python)
%o A333596 from itertools import accumulate
%o A333596 def A334841(n):
%o A333596     return 2*bin(n)[-1:1:-2].count('1')-(len(bin(n))-1)//2 if n > 0 else 0
%o A333596 A333596_list = list(accumulate(A334841(n) for n in range(10000))) # _Chai Wah Wu_, Sep 03 2020
%Y A333596 Cf. A053737, A010065, A037863, A268289, A007090, A231664, A301336, A334841.
%K A333596 nonn,base,easy
%O A333596 0,6
%A A333596 _Alexander Van Plantinga_, Mar 27 2020