Skip to content

Instantly share code, notes, and snippets.

@varyonic
Created June 11, 2011 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varyonic/1021054 to your computer and use it in GitHub Desktop.
Save varyonic/1021054 to your computer and use it in GitHub Desktop.
find largest three digit prime palindrome
def prime?(n)
for i in 2 ... n/2
return false if n % i == 0
end
true
end
def palindrome? n
s = n.to_s
s.slice( 0, (s.length+1)/2 ) == s.reverse.slice( 0, (s.length+1)/2 )
end
n = 999
n = n-1 while !prime?(n) or !palindrome?(n)
puts n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment