OFFSET
1,2
COMMENTS
It appears that all numbers will go to 1 eventually.
Count the iterations to reach 1, starting at k = n, using the following rule for each iteration: If k is divisible by 9, then divide it by 9; otherwise, concatenate the digit d = 9 - (k mod 9) to the end of k and divide by 9, unless k has already appeared during the iterative process; in this case, concatenate d with k and divide by 9.
Least n whose trajectory has no instance of repeated terms is 1; the trajectory of n=31 has 1 repeated term, and that of n=96 has 2 repeated terms. 2 repeated terms is the maximum for 1 <= n <= 2^18. Trajectories for all n in 1..2^20 eventually reach 1. - Michael De Vlieger, May 16 2021
Trajectories for all values of n between 1 and 10^8 eventually reach 1. - Kyle Peterson, May 19 2021
LINKS
Michael De Vlieger, Scatterplot of a(n) for n = 1..2^16.
Michael De Vlieger, Scatterplot of a(n) for n = 1..10^4, showing n with 1 repeated step in red and 2 repeated steps in blue, otherwise, a(n) is plotted in black.
Michael De Vlieger, Log-log scatterplot of a(n) for n = 1..2^18.
Michael De Vlieger, Plot of the steps in a(n) for n = 1..10^4, showing condition A (divisible by 9) in gold, condition B (concatenation of n and d) in light blue, and condition C (repeated step, concatenation of d and n) in red. Magnification is 4X.
EXAMPLE
n=7: start with k=7;
iteration 1: concatenate 7 with 9 - (7 mod 9) = 9 - 7 = 2 to get 72, then divide by 9, yielding k=8;
iteration 2: concatenate 8 with 9 - (8 mod 9) = 9 - 8 = 1 to get 81, then divide by 9, yielding k=9;
iteration 3: divide 9 by 9 to get k=1. k reaches 1 at iteration 3, so a(7)=3.
n=31: k=31 -> 315/9=35 -> 351/9=39 -> 396/9=44 -> 441/9=49 -> 495/9=55 -> 558/9=62 -> 621/9=69 -> 693/9=77 -> 774/9=86 -> 864/9=96 -> 963/9=107 -> 1071/9=119 -> 1197/9=133 -> 1332/9=148 -> 1485/9=165 -> 1656/9=184 -> 1845/9=205 -> 2052/9=228 -> 2286/9=254 -> 2547/9=283 -> 2835/9=315 -> 315/9=35 (*35 occurred at step 1*) -> 135/9=15 -> 153/9=17 -> 171/9=19 -> 198/9=22 -> 225/9=25 -> 252/9=28 -> 288/9=32 -> 324/9=36 -> 36/9=4 -> 45/9=5 -> 54/9=6 -> 63/9=7 -> 72/9=8 -> 81/9=9 -> 9/9=1, so a(31)=37.
MATHEMATICA
Array[-1 + Length@ NestWhile[Append[#1, If[Mod[#2, 9] == 0, #2/9, If[FreeQ[Most@ #1, #2], Select[10*#2 + Range[9], Mod[#, 9] == 0 &][[1]]/9, Select[10^IntegerLength[#2]*Range[9] + #2, Mod[#, 9] == 0 &][[1]]/9]] ] & @@ {#, Last[#]} &, {#}, Last[#] != 1 &] &, 73] (* Michael De Vlieger, May 16 2021 *)
PROG
(Python)
def a(n):
k, prevk, steps, seen = n, n, 0, set()
while k != 1:
q, r = divmod(k, 9)
if r == 0: k = q
elif k not in seen: k = int(str(k) + str(9-r))//9
else: k = int(str(9-r) + str(k))//9
steps, seen, prevk = steps+1, seen|{prevk}, k
return steps
print([a(n) for n in range(1, 74)]) # Michael S. Branicky, Jun 21 2021
CROSSREFS
KEYWORD
nonn,easy,base
AUTHOR
Kyle Peterson, May 16 2021
EXTENSIONS
More terms from Michael De Vlieger, May 16 2021
STATUS
approved