Skip to content

Instantly share code, notes, and snippets.

@tlowrimore
Created March 12, 2014 03:33
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 tlowrimore/9500335 to your computer and use it in GitHub Desktop.
Save tlowrimore/9500335 to your computer and use it in GitHub Desktop.
Detects whether a number is palindromic without converting the number to a String.
module Palindrome
def self.palindrome?(n)
n == reverse(n)
end
def self.reverse(n)
rs = 0
while n > 0
n, r = n.divmod 10
rs = rs * 10 + r
end
rs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment