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

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A334841 a(0) = 0; for n > 0, a(n) = (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). 2
0, 1, -1, 1, 0, 2, 0, 2, -2, 0, -2, 0, 0, 2, 0, 2, -1, 1, -1, 1, 1, 3, 1, 3, -1, 1, -1, 1, 1, 3, 1, 3, -3, -1, -3, -1, -1, 1, -1, 1, -3, -1, -3, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 3, 1, 3, -1, 1, -1, 1, 1, 3, 1, 3, -2, 0, -2, 0, 0, 2, 0, 2, -2, 0, -2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 4, 2, 4, 0 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,6

COMMENTS

Values are even for base 4 representations of n with an even number of digits, and odd for base 4 representations of n with an odd number of digits, except for a(0).

LINKS

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

FORMULA

a(n) = 2*A139351(n) - A110592(n), n>0. - R. J. Mathar, Sep 02 2020

EXAMPLE

      n in    #odd    #even

  n  base 4  digits - digits = a(n)

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

  0    0        0   -            0

  1    1        1   -    0   =   1

  2    2        0   -    1   =  -1

  3    3        1   -    0   =   1

  4   10        1   -    1   =   0

  5   11        2   -    0   =   2

  6   12        1   -    1   =   0

  7   13        2   -    0   =   2

MAPLE

a:= n-> `if`(n=0, 0, add(`if`(i in [1, 3], 1, -1), i=convert(n, base, 4))):

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

MATHEMATICA

a[0] = 0; a[n_] := Total[-(-1)^(r = Range[0, 3]) * DigitCount[n, 4, r]]; Array[a, 100, 0] (* Amiram Eldar, May 13 2020 *)

Join[{0}, Table[Total[If[EvenQ[#], -1, 1]&/@IntegerDigits[n, 4]], {n, 90}]] (* Harvey P. Dale, Sep 06 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)

}

(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(t))

(PARI) a(n) = my(ret=0); if(n, forstep(i=0, logint(n, 2), 2, if(bittest(n, i), ret++, ret--))); ret; \\ Kevin Ryde, May 24 2020

(Python)

def A334841(n):

    return 2*bin(n)[-1:1:-2].count('1')-(len(bin(n))-1)//2 if n > 0 else 0 # Chai Wah Wu, Sep 03 2020

CROSSREFS

Cf. A053737, A010065, A037863, A007090, A301336, A333596.

Sequence in context: A106277 A088627 A230205 * A024713 A123530 A161516

Adjacent sequences:  A334838 A334839 A334840 * A334842 A334843 A334844

KEYWORD

sign,easy,base

AUTHOR

Alexander Van Plantinga, May 13 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 July 27 02:39 EDT 2021. Contains 346302 sequences. (Running on oeis4.)