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

%I #33 Sep 06 2020 19:04:54

%S 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,

%T 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,

%U -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

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

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

%F a(n) = 2*A139351(n) - A110592(n), n>0. - _R. J. Mathar_, Sep 02 2020

%e n in #odd #even

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

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

%e 0 0 0 - 0

%e 1 1 1 - 0 = 1

%e 2 2 0 - 1 = -1

%e 3 3 1 - 0 = 1

%e 4 10 1 - 1 = 0

%e 5 11 2 - 0 = 2

%e 6 12 1 - 1 = 0

%e 7 13 2 - 0 = 2

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

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

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

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

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

%o (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

%o (Python)

%o def A334841(n):

%o 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

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

%K sign,easy,base

%O 0,6

%A _Alexander Van Plantinga_, May 13 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 March 29 00:26 EDT 2024. Contains 371264 sequences. (Running on oeis4.)