Skip to content

Instantly share code, notes, and snippets.

@mosdevly
Last active August 29, 2015 14:08
Show Gist options
  • Save mosdevly/a1104b89ae98f8de40f8 to your computer and use it in GitHub Desktop.
Save mosdevly/a1104b89ae98f8de40f8 to your computer and use it in GitHub Desktop.
Given a string determine if it's a palindrome. Ignore case and include only alphanumeric characters (no punctuation or diacritical marks).
def rev(str)
a = 0
reverse = ""
while a < str.length
reverse = str[a] + reverse
a += 1
end
puts "#{str} backwards is #{reverse}."
if reverse == str
puts "#{reverse} is a palindrome."
else
puts "#{reverse} is not a palindrome."
end
end
puts rev("dogs")
puts rev("reciprocity")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment