Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created January 20, 2021 02:08
Show Gist options
  • Save ZechCodes/75712a4bfdc591411e8fe42071a4c5d9 to your computer and use it in GitHub Desktop.
Save ZechCodes/75712a4bfdc591411e8fe42071a4c5d9 to your computer and use it in GitHub Desktop.
Challenge 168 - Count Palindrome Numbers

Challenge 168 - Count Palindrome Numbers

Create a function that returns the number of palindrome numbers in a specified range (inclusive).

For example, between 8 and 34, there are 5 palindromes: 8, 9, 11, 22, and 33. Between 1550 and 1552 there is exactly one palindrome: 1551.

Examples

count_palindromes(1, 10) ➞ 9

count_palindromes(555, 556) ➞ 1

count_palindromes(878, 898) ➞ 3

Notes

  • Single-digit numbers are trivially palindrome numbers.
import unittest
def count_palindromes(range_start: int, range_end: int) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(count_palindromes(1, 10), 9)
def test_2(self):
self.assertEqual(count_palindromes(555, 556), 1)
def test_3(self):
self.assertEqual(count_palindromes(878, 898), 3)
def test_4(self):
self.assertEqual(count_palindromes(8, 34), 5)
def test_5(self):
self.assertEqual(count_palindromes(1550, 1556), 1)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment