Skip to content

Instantly share code, notes, and snippets.

@carbonphyber
Created April 30, 2011 17:59
Show Gist options
  • Save carbonphyber/949837 to your computer and use it in GitHub Desktop.
Save carbonphyber/949837 to your computer and use it in GitHub Desktop.
Ruby function to detect if a Fixednum is a palendrome.
# @author David Wortham <djwortham+programming@gmail.com>
# @date 2011-04-30
# @license MIT License: http://www.opensource.org/licenses/mit-license.php
def isPalendrome(number)
numberStr = number.to_s()
return false if numberStr.empty? || numberStr.length < 0
return true if numberStr.length < 2
lCursor = 0
rCursor = numberStr.length - 1
while lCursor < rCursor
return false if numberStr.getbyte(lCursor) != numberStr.getbyte(rCursor)
lCursor = lCursor + 1
rCursor = rCursor - 1
end
return true
end
# usage
# puts "111 is a palendrome? #{isPalendrome(111)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment