Skip to content

Instantly share code, notes, and snippets.

@maxjacobson
Created February 8, 2013 21:36
Show Gist options
  • Save maxjacobson/4742133 to your computer and use it in GitHub Desktop.
Save maxjacobson/4742133 to your computer and use it in GitHub Desktop.
def is_palindrome? whatsit
str = whatsit.to_s.downcase.gsub(/ |[^\w\d]|\n/, '')
str == str.reverse ? true : false
end
to_check = [
"a man, a plan, a canal: panama",
"Mr. Owl Ate My Metal Worm",
909,
100,
"sup jamal",
"racecar
racecar"
]
to_check.each do |checker|
if is_palindrome? checker
puts "a palindrome: #{checker}"
else
puts "not a palindrome: #{checker}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment