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.
%I A334841 #35 Jan 27 2025 08:47:41 %S A334841 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 A334841 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 A334841 -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 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). %C A334841 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 A334841 a(n) = 2*A139351(n) - A110591(n), n>0. - _R. J. Mathar_, Sep 02 2020 %e A334841 n in #odd #even %e A334841 n base 4 digits - digits = a(n) %e A334841 = ====== ======================= %e A334841 0 0 0 - 0 %e A334841 1 1 1 - 0 = 1 %e A334841 2 2 0 - 1 = -1 %e A334841 3 3 1 - 0 = 1 %e A334841 4 10 1 - 1 = 0 %e A334841 5 11 2 - 0 = 2 %e A334841 6 12 1 - 1 = 0 %e A334841 7 13 2 - 0 = 2 %p A334841 a:= n-> `if`(n=0, 0, add(`if`(i in [1, 3], 1, -1), i=convert(n, base, 4))): %p A334841 seq(a(n), n=0..100); # _Alois P. Heinz_, May 30 2020 %t A334841 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 A334841 Join[{0},Table[Total[If[EvenQ[#],-1,1]&/@IntegerDigits[n,4]],{n,90}]] (* _Harvey P. Dale_, Sep 06 2020 *) %o A334841 (R) %o A334841 qnary = function(n, e, q){ %o A334841 e = floor(n/4) %o A334841 q = n%%4 %o A334841 if(n == 0 ){return(0)} %o A334841 if(e == 0){return(q)} %o A334841 else{return(c(qnary(e), (q)))} %o A334841 } %o A334841 m = 400 %o A334841 s = seq(2, m) %o A334841 v = c(0) %o A334841 for(i in s){ %o A334841 x = qnary(i-1) %o A334841 x[which(x%%2!=0)] = 1 %o A334841 x[which(x%%2==0)] = -1 %o A334841 v[i] = sum(x) %o A334841 } %o A334841 (Python) %o A334841 import numpy as np %o A334841 def qnary(n): %o A334841 e = n//4 %o A334841 q = n%4 %o A334841 if n == 0 : return 0 %o A334841 if e == 0 : return q %o A334841 if e != 0 : return np.append(qnary(e), q) %o A334841 m = 400 %o A334841 v = [0] %o A334841 for i in range(1, m+1) : %o A334841 t = np.array(qnary(i)) %o A334841 t[t%2 != 0] = 1 %o A334841 t[t%2 == 0] = -1 %o A334841 v = np.append(v, np.sum(t)) %o A334841 (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 A334841 (Python) %o A334841 def A334841(n): %o A334841 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 A334841 Cf. A053737, A010065, A037863, A007090, A301336, A333596. %K A334841 sign,easy,base %O A334841 0,6 %A A334841 _Alexander Van Plantinga_, May 13 2020