OFFSET
0,3
COMMENTS
a(n) = How many numbers whose base-3 representation begins with digit "1" are encountered before (3^n)-1 is reached when starting from k = (3^(n+1))-1 and repeatedly applying the map that replaces k by k - (sum of digits in base-3 representation of k).
EXAMPLE
For n=2, we start from 3^(2+1) - 1 = 26 ("222" in base-3), and subtract 6 to get 20 ("202" in base-3), from which we subtract 4, to get 16 ("121" in base-3), from which we subtract 4, to get 12 ("110" in base-3), from which we subtract 2 to get 10 ("101" in base-3), from which we subtract 2 to get 8 ("22" in base-3), which is the end point of iteration. Of the numbers encountered, 16, 12 and 10 have base-3 representations beginning with digit "1", thus a(2) = 3.
MATHEMATICA
Table[Length@ # - First@ FirstPosition[#, k_ /; k != 2] &@ Map[First@ IntegerDigits[#, 3] &, #] &@ NestWhileList[# - Total@ IntegerDigits[#, 3] &, 3^(n + 1) - 1, # > 3^n - 1 &], {n, 0, 16}] (* Michael De Vlieger, Jun 27 2016, Version 10 *)
PROG
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Aug 16 2015
EXTENSIONS
Terms a(24) & a(25) from Antti Karttunen, Jun 27 2016
STATUS
approved