Created
April 24, 2013 21:15
-
-
Save maltzsama/5455641 to your computer and use it in GitHub Desktop.
Challenge Description: Write a program to determine the biggest prime palindrome under 1000.
Input sample: None
Output sample: Your program should print the largest palindrome on stdout. i.e.
929
This file contains hidden or 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
| #!/usr/bin/env python | |
| def isprime(n): | |
| for x in xrange(2, int(n**0.5)+1): | |
| if n % x == 0: | |
| return False | |
| return True | |
| def palindrome(n): | |
| if str(n) == str(n)[::-1]: | |
| return True | |
| else: | |
| return False | |
| x = 0 | |
| for n in range(1, 1001): | |
| if isprime(n): | |
| if palindrome(n): | |
| x = n | |
| print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment