%I #42 Jul 13 2024 21:44:07
%S 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,
%T 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,
%U 3,4,4,3,2,3,3,3,2,3,2,2,1,2,3,3,4,3,4,4,4,3
%N Number of runs in base-3 representation of n.
%C Every positive integer occurs infinitely many times. See A297770 for a guide to related sequences.
%C 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
%C From _M. F. Hasler_, Jul 13 2024: (Start)
%C 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'.
%C "Runs" means substrings of consecutive equal digits, here in the base-3 representation of the numbers. See Example for details. (End)
%H Alois P. Heinz, <a href="/A043555/b043555.txt">Table of n, a(n) for n = 0..19682</a> (first 1001 terms from Zak Seidov)
%e From _M. F. Hasler_, Jul 13 2024: (Start)
%e 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.
%e 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.
%e In '11' we have again one single run, here of 2 digits '1', whence a(4) = 1. (End)
%p NRUNS := proc(L::list)
%p local a,i;
%p a := 1 ;
%p for i from 2 to nops(L) do
%p if op(i,L) <> op(i-1,L) then
%p a := a+1 ;
%p end if
%p end do:
%p a ;
%p end proc:
%p A043555 := proc(n)
%p convert(n,base,3) ;
%p NRUNS(%) ;
%p end proc:
%p seq(A043555(n),n=0..80) ; # _R. J. Mathar_, Jul 12 2024
%p # second Maple program:
%p a:= n-> `if`(n<3, 1, a(iquo(n, 3))+`if`(n mod 9 in {0, 4, 8}, 0, 1)):
%p seq(a(n), n=0..89); # _Alois P. Heinz_, Jul 13 2024
%t b = 3; s[n_] := Length[Split[IntegerDigits[n, b]]];
%t Table[s[n], {n, 1, 200}]
%o (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
%o (Python)
%o from itertools import groupby
%o from sympy.ntheory import digits
%o def A043555(n): return len(list(groupby(digits(n,3)[1:]))) # _Chai Wah Wu_, Jul 13 2024
%Y Cf. A005811 (in base 2), A043556 (in base 4), A145204, A297770, A297771 (number of distinct runs).
%Y Cf. A033113.
%K nonn,base,easy
%O 0,4
%A _Clark Kimberling_
%E Updated by _Clark Kimberling_, Feb 03 2018