cp's OEIS Frontend

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.

A272896 Difference between the number of odd and even digits in the decimal expansion of 2^n.

Original entry on oeis.org

1, -1, -1, -1, 0, 0, -2, -1, -1, 1, -2, -4, -2, 0, -1, -1, 1, 2, -4, -4, -1, 1, -1, -5, 2, 2, -4, 1, -3, 1, 0, -4, -2, 2, 3, 3, 1, 4, -2, 2, 5, 3, -1, -5, -2, -2, -2, 1, -1, 3, -4, 0, 2, 2, -1, -1, 5, 2, 2, -4, -3, 1, -5, -1, 0, 0, -6, 3, 5, 5, 2, -10, -8, 2, -3, 7, 9, 0, 0
Offset: 0

Views

Author

Seiichi Manyama, May 09 2016

Keywords

Comments

All vanishing entries are a(A272898(k)) = 0, k >= 1. - Wolfdieter Lang, May 24 2016

Examples

			2^10 = 1024, 2^11 = 2048, 2^12 = 4096, 2^13 = 8192.
So a(10) = 1 - 3 = -2, a(11) = 0 - 4 = -4, a(12) = 1 - 3 = -2, a(13) = 2 - 2 = 0.
		

Crossrefs

Programs

  • Mathematica
    Table[Count[#, ?OddQ] - Count[#, ?EvenQ] &@ IntegerDigits[2^n], {n, 0, 100}] (* Michael De Vlieger, May 09 2016 *)
  • PARI
    a(n) = #select(x -> x%2, digits(2^n)) - #select(x -> !(x%2), digits(2^n));
    for(n=0, 78, print1(a(n),", ")) \\ Indranil Ghosh, Mar 13 2017
    
  • Python
    def A272896(n):
        x=y=0
        for i in str(2**n):
            if int(i)%2: x+=1
            else: y+=1
        return x - y # Indranil Ghosh, Mar 13 2017
  • Ruby
    def a(n)
      str = (2 ** n).to_s
      str.size - str.split('').map(&:to_i).select{|i| i % 2 == 0}.size * 2
    end
    (0..n).each{|i| p a(i)}
    

Formula

a(n) = A055254(n) - A055253(n) = A196564(2^n) - A196563(2^n). - Indranil Ghosh, Mar 13 2017