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.

Showing 1-3 of 3 results.

A180094 Number of steps to reach 0 or 1, starting with n and applying the map k -> (number of 1's in binary expansion of k) repeatedly.

Original entry on oeis.org

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

Views

Author

Joerg Arndt, Jan 15 2011

Keywords

Comments

The number of 1's in binary expansion of n is called the binary weight (or Hamming weight) of n, A000120(n).
a(n)=0 for n=0 and n=1; a(n)=1 for powers of 2.
Records appear for n = 2, 3, 7, 127=2^7-1, 2^127-1, ... (terms of A007013).
It appears that the indices of the even terms for n>0 are sequence A075311.

Crossrefs

One less than A078627.

Programs

  • Haskell
    a180094 n = snd $ until ((< 2) . fst) (\(x, c) -> (a000120 x, c+1)) (n,0)
    -- Reinhard Zumkeller, Apr 22 2011
    
  • Magma
    Countbits:=func< n | &+Intseq(n, 2) >;
    StepsTo01:=function(n); s:=0; k:=n; while k gt 1 do k:=Countbits(k); s+:=1; end while; return s; end function;
    [ StepsTo01(n): n in [0..105] ]; // Klaus Brockhaus, Jan 15 2011
    
  • Maple
    a:= n-> `if`(n<2, 0, 1 + a(add(i, i=convert(n, base, 2)))):
    seq(a(n), n=0..100);  # Alois P. Heinz, Jan 15 2011
  • Mathematica
    Table[Length[NestWhileList[DigitCount[#,2,1]&,n,#>1&]]-1,{n,0,100}] (* Harvey P. Dale, Jul 27 2012 *)
  • PARI
    bitcount(x)=
    { /* Return Hamming weight of x, i.e. A000120(x) */
        local(p);  p = 0;
        while ( x, p+=bitand(x, 1); x>>=1; );
        return( p );
    }
    X(n)=
    { /* Return how many iterations of bitcount() are needed to reach 0 or 1 */
        if ( n<=1, return(0) );
        return( 1+X(bitcount(n)) );
    }
    { for (n=0, 100, print1(X(n),", ") ); } /* print terms of sequence */
    
  • Python
    def a(n):
        c = 1 if n > 1 else 0
        while (n:=n.bit_count()) > 1:
            c += 1
        return c
    print([a(n) for n in range(101)]) # Michael S. Branicky, Mar 12 2025

A381962 Irregular triangle read by rows, where row n lists the iterates of f(x), starting at x = n until f(x) <= 1, where f(x) is the Hamming weight of x (A000120).

Original entry on oeis.org

0, 1, 2, 1, 3, 2, 1, 4, 1, 5, 2, 1, 6, 2, 1, 7, 3, 2, 1, 8, 1, 9, 2, 1, 10, 2, 1, 11, 3, 2, 1, 12, 2, 1, 13, 3, 2, 1, 14, 3, 2, 1, 15, 4, 1, 16, 1, 17, 2, 1, 18, 2, 1, 19, 3, 2, 1, 20, 2, 1, 21, 3, 2, 1, 22, 3, 2, 1, 23, 4, 1, 24, 2, 1, 25, 3, 2, 1, 26, 3, 2, 1
Offset: 0

Views

Author

Paolo Xausa, Mar 11 2025

Keywords

Examples

			Triangle begins:
  n\k|  0  1  2  3
  ----------------
   0 |  0;
   1 |  1;
   2 |  2, 1;
   3 |  3, 2, 1;
   4 |  4, 1;
   5 |  5, 2, 1;
   6 |  6, 2, 1;
   7 |  7, 3, 2, 1;
   8 |  8, 1;
   9 |  9, 2, 1;
  10 | 10, 2, 1;
  ...
		

Crossrefs

Cf. A000120, A078627 (row lengths), A078677 (row sums), A180094.

Programs

  • Mathematica
    A381962row[n_] := NestWhileList[DigitSum[#, 2] &, n, # > 1 &];
    Array[A381962row, 30, 0]
  • Python
    def row(n):
        out = [n] if n > 1 else []
        while (n:=n.bit_count()) > 1:
            out += [n]
        return out + [n]
    print([e for n in range(27) for e in row(n)]) # Michael S. Branicky, Mar 12 2025

Formula

T(n,0) = n and, for k = 1..A180094(n), T(n,k) = A000120(T(n,k-1)).

A078677 Write n in binary; repeatedly sum the "digits" until reaching 1; a(n) = sum of these sums (including '1' and n itself).

Original entry on oeis.org

1, 3, 6, 5, 8, 9, 13, 9, 12, 13, 17, 15, 19, 20, 20, 17, 20, 21, 25, 23, 27, 28, 28, 27, 31, 32, 32, 34, 34, 35, 39, 33, 36, 37, 41, 39, 43, 44, 44, 43, 47, 48, 48, 50, 50, 51, 55, 51, 55, 56, 56, 58, 58, 59, 63, 62, 62, 63, 67, 65, 69, 70, 72, 65, 68, 69, 73, 71, 75, 76, 76, 75
Offset: 1

Views

Author

Frank Schwellinger (nummer_eins(AT)web.de), Dec 17 2002

Keywords

Examples

			a(13) = 19 because 13 = (1101) -> (1+1+0+1 = 11) -> (1+1 = 10) -> (1+0 = 1) = 1 and 1101+11+10+1 (binary) = 19 (decimal).
		

Crossrefs

Row sums of A381962.

Programs

  • Mathematica
    A078677[n_] := Total[NestWhileList[DigitSum[#, 2] &, n, # > 1 &]];
    Array[A078677, 100] (* Paolo Xausa, Mar 11 2025 *)
  • Python
    def a(n):
        s = n if n > 1 else 0
        while (n:=n.bit_count()) > 1:
            s += n
        return s + 1
    print([a(n) for n in range(1, 73)]) # Michael S. Branicky, Mar 12 2025

Formula

a(1) = 1; for n > 1, a(n) = n + a(A000120(n)).
a(n) = Sum_{k = 0..A180094(n)} A381962(n,k). - Paolo Xausa, Mar 12 2025
Showing 1-3 of 3 results.