Reduce an integer to a single digit by recursively multiplying its digits

170 Views Asked by At

Given a positive integer $n_0$, the product of all its digits gives a new number $n_1$, which is smaller than $n_0$. Repeating this operation eventually reduces the original number to a single digit $n_\infty \in [0, 9]$.

I wrote the following code to perform this operation and tested it on integers in [0, 10 000). The result is plotted below. Visually I spotted no pattern, and wonders if any pattern exists at all. I posted it here due to my little knowledge of number theory --- also sorry if this is a well-known problem already. Thanks!

Note: one can sum the digits instead of multiplying them, which gives a related question.

def productDigits(n):
    prod = 1
    while(n):
        prod *= (n%10)
        n //= 10
    return prod

def convert(n):
    while n > 9:
        n = productDigits(n)
    return n

# print(productDigits(82))
# print(productDigits(39))

# for i in range(11, 100):
#     print(i, ' => ', convert(i))

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10000)
y = np.array(list(convert(i) for i in x))

plt.plot(x,y)
plt.xlim(0, 10000)
plt.ylim(0, 10)
plt.show()

operation applied to 0 to 10000

update: as was pointed by Gerry Myerson in the comment, this sequence can be found at https://oeis.org/A031347. The single digit that $n$ reduces to is called $n$'s multiplicative digital root, and the number of recursions took is its multiplicative persistence. Similiar concepts exist if sum is used instead of multiplication.