Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Integer Palindrome by freixodachamorra
from math import log
def int_palindrome(number: int) -> bool:
numciphers = int(log(number, 10)+1)
maxiter = numciphers // 2
num2 = number
for i in range(1, maxiter+1):
cipher = number // 10 ** (numciphers-i) % 10
cipher2 = num2 % 10
if cipher != cipher2:
return False
num2 = num2 // 10
return True
print("Example:")
print(int_palindrome(151))
assert int_palindrome(151) == True
assert int_palindrome(212) == True
assert int_palindrome(321) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 26, 2022