generate functionTue, 14 Feb 2023

Let's take a number. Let's multiply it by its first digit. The result is multiplied by the first digit of the result. And so on. Obviously, when the first digit of the next number in such a sequence becomes equal to 1, the numbers stop changing. But this does not happen for all initial numbers. Let's write a program that will at least approximately determine the fate of the entered number n. Starting with the number n, multiply the given number by its first digit until the resulting number has the first digit equal to 1, or until it exceeds a billion. Output the result as an answer.

def first_digit(n): while n > 1 and n < 10**9: n = n * (n // 10) return n

Questions about programming?Chat with your personal AI assistant