Skip to content

Instantly share code, notes, and snippets.

@aasmpro
Created February 14, 2022 23:52
Show Gist options
  • Save aasmpro/8b42768a2e8469357fc9a2ef06defabd to your computer and use it in GitHub Desktop.
Save aasmpro/8b42768a2e8469357fc9a2ef06defabd to your computer and use it in GitHub Desktop.
Python - Validate Palindrome Mathematically (numbers only of course)
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