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-2 of 2 results.

A297770 Number of distinct runs in base-2 digits of n.

Original entry on oeis.org

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

Views

Author

Clark Kimberling, Jan 26 2018

Keywords

Comments

Every positive integers occurs infinitely many times.
***
Guide to related sequences:
Base b # runs # distinct runs

Examples

			27 in base-2: 1,1,0,1,1; three runs, of which 2 are distinct:  0 and 11, so that a(27) = 2.
		

Crossrefs

Cf. A005811 (number of runs, not necessarily distinct).

Programs

  • Mathematica
    b = 2; s[n_] := Length[Union[Split[IntegerDigits[n, b]]]]
    Table[s[n], {n, 1, 200}]
  • PARI
    apply( {A297770(n)=my(r=[0,0], c); while(n, my(d=bitand(n,1), L=valuation(n+d, 2)); !bittest(r[1+d], L) && c++ && r[1+d] += 1<>=L); c}, [0..99]) \\ M. F. Hasler, Jul 13 2024
    
  • PARI
    a(n) = my(s=strjoin(binary(n)), v=vecsort(concat(strsplit(s, "1"), strsplit(s, "0")), , 8)); #v-(v[1]==""); \\ Ruud H.G. van Tol, Aug 05 2024
  • Python
    from itertools import groupby
    def A297770(n): return len(set(map(lambda x:tuple(x[1]),groupby(bin(n)[2:])))) # Chai Wah Wu, Jul 13 2024
    

A043555 Number of runs in base-3 representation of n.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Every positive integer occurs infinitely many times. See A297770 for a guide to related sequences.
Having a(0) = 1 (rather than a(0) = 0) is debatable, on the grounds that a(0) = 1 is determined by our culture, rather than the underlying mathematics. See my August 2020 comment in A145204. - Peter Munn, Jul 12 2024
From M. F. Hasler, Jul 13 2024: (Start)
The base-2 version has a(0) = 0, corresponding to the convention that 0 has zero digits, which is the more logical (but maybe less human) convention, such that, e.g., b^n is the least number with n+1 digits in base b (<=> b^n - 1 is the largest number with n digits), valid also for 0. Here and in A043556 (base 4) the convention is that 0 has one digit, '0'.
"Runs" means substrings of consecutive equal digits, here in the base-3 representation of the numbers. See Example for details. (End)

Examples

			From _M. F. Hasler_, Jul 13 2024: (Start)
Numbers n = 0, 1, 2, 3, 4, 5, ... are written '0', '1', '2', '10', '11', '12', ... in base 3. The first three have one single digit, so there is just 1 "run" (= subsequence of equal digits), whence a(0) = a(1) = a(2) = 1.
In '10' we have a "run" of '1's of length 1, followed by a run of '0's of length 1, so there are a(3) = 2 runs.
In '11' we have again one single run, here of 2 digits '1', whence a(4) = 1. (End)
		

Crossrefs

Cf. A005811 (in base 2), A043556 (in base 4), A145204, A297770, A297771 (number of distinct runs).
Cf. A033113.

Programs

  • Maple
    NRUNS := proc(L::list)
        local a,i;
        a := 1 ;
        for i from 2 to nops(L) do
            if op(i,L) <> op(i-1,L) then
                a := a+1 ;
            end if
        end do:
        a ;
    end proc:
    A043555 := proc(n)
        convert(n,base,3) ;
        NRUNS(%) ;
    end proc:
    seq(A043555(n),n=0..80) ; # R. J. Mathar, Jul 12 2024
    # second Maple program:
    a:= n-> `if`(n<3, 1, a(iquo(n, 3))+`if`(n mod 9 in {0, 4, 8}, 0, 1)):
    seq(a(n), n=0..89);  # Alois P. Heinz, Jul 13 2024
  • Mathematica
    b = 3; s[n_] := Length[Split[IntegerDigits[n, b]]];
    Table[s[n], {n, 1, 200}]
  • PARI
    a(n)=my(d=digits(n,3)); sum(i=2,#d,d[i]!=d[i-1])+1 \\ Charles R Greathouse IV, Jul 20 2014
    
  • Python
    from itertools import groupby
    from sympy.ntheory import digits
    def A043555(n): return len(list(groupby(digits(n,3)[1:]))) # Chai Wah Wu, Jul 13 2024

Extensions

Updated by Clark Kimberling, Feb 03 2018
Showing 1-2 of 2 results.