OFFSET
0,3
COMMENTS
For all numbers n, the iterated map n -> a(n) gives a loop of numbers linked by permutations of their digits, consisting of k-cycles, with k always odd. Indeed, for k even, each iteration divides k by 2. After a few steps, we obtain a fixed point or a loop of 2, 3, 4 or 6, generated respectively by:
- the identity,
- 2 permutations consisting of one, two or three 3-cycle,
- 3 permutations of 7-cycle,
- 4 permutations of 5-cycle,
- 6 permutations of 9-cycle.
Thus, the smallest numbers n giving such loops are respectively 0, 231, 2345671, 23451 and 234567891. There is no step before loop of 6 because the permutation applies directly to all nonzero digits. Also applicable to other bases, the loop length is the least common multiple of multiplicative orders of 2 modulo the different values of k.
LINKS
Stéphane Rézel, Table of n, a(n) for n = 0..10000
EXAMPLE
For n=23, the digit 2 is replaced by three, because it is the second digit of n. Next, the digit 3 cannot be replaced directly because n has no third digit. After counting the first two digits of n, the indexing resumes at the first digit of n which corresponds here to the third ordinal: the digit 3 is thus replaced by two. In summary: a(23) = {2nd digit of n, 1st digit of n} = {3, 2} = 32.
a(2056748) = {0, 0, 7, 4, 8, 6, 2} = 74862.
MATHEMATICA
Array[FromDigits@ Map[# /. k_ /; ! IntegerQ@ k -> 0 &, PadRight[#, 9, #][[#]]] &@ IntegerDigits[#] &, 67] (* Michael De Vlieger, Sep 30 2019 *)
PROG
(PARI) a(n) = {if (n==0, return (0)); my(s = Str(n), d=digits(n)); if (#s < 9, my(i=1); while (#s < 9, s = concat(s, d[i]); i++; if (i>#d, i=1))); my(dm = digits(eval(s))); my(ns=""); for (i=1, #d, if (dm[i], ns = concat(ns, dm[dm[i]]), ns = concat(ns, 0)); ); eval(ns); } \\ Michel Marcus, Sep 30 2019
CROSSREFS
KEYWORD
AUTHOR
Stéphane Rézel, Sep 29 2019
STATUS
approved