Skip to content

Instantly share code, notes, and snippets.

@dhiachou
Last active April 14, 2017 12:05
Show Gist options
  • Save dhiachou/98e9e29816cdc913a1a01e261b1b66ed to your computer and use it in GitHub Desktop.
Save dhiachou/98e9e29816cdc913a1a01e261b1b66ed to your computer and use it in GitHub Desktop.
require 'prime'
class Integer
# Monkey patch to check if n is palindromic
def is_palindrome?
self.to_s == self.to_s.reverse
end
end
# Prints the first n palindromic prime int
n = STDIN.gets.chomp.to_i
puts "#{Prime.lazy.select{|e| e.is_palindrome?}.first(n)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment