Reverse and Add
There is a curious process: take a number, add its digit-reversed form, and repeat. Write a function is_lychrel that returns True if no palindrome appears after max_iter iterations, treating the number as a Lychrel candidate. If a palindrome appears earlier, return False. Checking a palindrome is easy by comparing a string with its reverse.
Примеры
Ввод
47, 50Вывод
FalseВвод
349, 50Вывод
FalseВвод
89, 50Вывод
FalseНужно реализовать
def is_lychrel(n: int, max_iter: int) -> bool:
Теги
mathstrings
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
47, 50Expected
False2
Input
349, 50Expected
False3
Input
89, 50Expected
False4
Input
196, 50Expected
True5
Input
4994, 50Expected
True6
Input
10, 50Expected
FalseFocus radio
Paused · SomaFM · Fluid