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.

A081603 Number of 2's in ternary representation of n.

Original entry on oeis.org

0, 0, 1, 0, 0, 1, 1, 1, 2, 0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 0, 0, 1, 0, 0, 1, 1, 1, 2, 0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, 3, 3, 4, 0, 0, 1, 0, 0, 1, 1, 1, 2, 0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2
Offset: 0

Views

Author

Reinhard Zumkeller, Mar 23 2003

Keywords

Comments

Fixed point of the morphism: 0 ->001; 1 ->112; 2 ->223; 3 ->334, etc., starting from a(0)=0. - Philippe Deléham, Oct 26 2011

Crossrefs

Programs

  • Haskell
    a081603 0 = 0
    a081603 n = a081603 n' + m `div` 2 where (n',m) = divMod n 3
    -- Reinhard Zumkeller, Feb 21 2013
    
  • Maple
    A081603 := proc(n)
        local a,d ;
        a := 0 ;
        for d in convert(n,base,3) do
            if d= 2 then
                a := a+1 ;
            end if;
        end do:
        a;
    end proc: # R. J. Mathar, Jul 12 2016
  • Mathematica
    Table[Count[IntegerDigits[n,3],2],{n,0,6!}] (* Vladimir Joseph Stephan Orlovsky, Jul 25 2009 *)
    Nest[ Flatten[# /. a_Integer -> {a, a, a + 1}] &, {0}, 5] (* Robert G. Wilson v, May 20 2014 *)
    DigitCount[Range[0,120],3,2] (* Harvey P. Dale, Jul 10 2019 *)
  • PARI
    a(n)=hammingweight(digits(n,3)\2); \\ Ruud H.G. van Tol, Dec 10 2023
    
  • Python
    from gmpy2 import digits
    def A081603(n): return digits(n,3).count('2') # Chai Wah Wu, Dec 05 2024

Formula

a(n) = floor(n/2) if n < 3, otherwise a(floor(n/3)) + floor((n mod 3)/2).
A077267(n) + A062756(n) + a(n) = A081604(n);
a(n) = (A053735(n) - A062756(n))/2.