login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

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
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).
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
KEYWORD
sign,easy,base
AUTHOR
STATUS
approved