Created
February 14, 2022 23:52
-
-
Save aasmpro/8b42768a2e8469357fc9a2ef06defabd to your computer and use it in GitHub Desktop.
Python - Validate Palindrome Mathematically (numbers only of course)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome(number): | |
test_number = 0 | |
length = math.ceil(math.log10(number + 1)) | |
for i in range(length // 2): | |
test_number = (test_number * 10) + (number % 10) | |
number //= 10 | |
return number == test_number or number // 10 == test_number | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment