Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Created April 24, 2013 21:15
Show Gist options
  • Select an option

  • Save maltzsama/5455641 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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