login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.

 

Logo

Thanks to everyone who made a donation during our annual appeal!
To see the list of donors, or make a donation, see the OEIS Foundation home page.

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
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, 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, 13, 12, 13, 14, 17, 18, 21, 19, 19, 17, 17, 17, 19, 19, 21, 19, 19 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,6

COMMENTS

Local maxima values minus 1 are divisible by 4.

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

LINKS

Table of n, a(n) for n=0..73.

EXAMPLE

      n in    #odd    #even

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

  =  ======  ===============================

  0    0        0   -                     0

  1    1        1   -    0   +    0   =   1

  2    2        0   -    1   +    1   =   0

  3    3        1   -    0   +    0   =   1

  4   10        1   -    1   +    1   =   1

  5   11        2   -    0   +    1   =   3

  6   12        1   -    1   +    3   =   3

  7   13        2   -    0   +    3   =   5

MAPLE

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

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

    end:

seq(a(n), n=0..80);  # Alois P. Heinz, May 30 2020

MATHEMATICA

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

PROG

(R)

qnary = function(n, e, q){

  e = floor(n/4)

  q = n%%4

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

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

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

}

m = 400

s = seq(2, m)

v = c(0)

for(i in s){

  x = qnary(i-1)

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

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

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

}

(Python)

import numpy as np

def qnary(n):

    e = n//4

    q = n%4

    if n == 0 : return 0

    if e == 0 : return q

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

m = 400

v = [0]

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

    t = np.array(qnary(i))

    t[t%2 != 0] = 1

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

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

(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

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

first(n)=my(s); concat(0, vector(n, k, s+=b(k))) \\ Charles R Greathouse IV, Jul 04 2020

(Python)

from itertools import accumulate

def A334841(n):

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

A333596_list = list(accumulate(A334841(n) for n in range(10000))) # Chai Wah Wu, Sep 03 2020

CROSSREFS

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

Sequence in context: A302141 A077924 A003569 * A066670 A282270 A013606

Adjacent sequences:  A333593 A333594 A333595 * A333597 A333598 A333599

KEYWORD

nonn,base,easy

AUTHOR

Alexander Van Plantinga, Mar 27 2020

STATUS

approved

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified January 19 10:37 EST 2021. Contains 340269 sequences. (Running on oeis4.)