A043555 Number of runs in base-3 representation of n.
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
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)
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..19682 (first 1001 terms from Zak Seidov)
Crossrefs
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
Comments