Created
April 3, 2013 18:33
-
-
Save irissilvermoon/5303865 to your computer and use it in GitHub Desktop.
palindrome program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def palindrome?(string) | |
head = 0 | |
tail = string.length - 1 | |
while string[head] == string[tail] | |
head += 1 | |
tail -= 1 | |
if tail < head | |
puts 'palindrome' | |
else | |
puts 'not palindrome' | |
end | |
end | |
end | |
palindrome?("racecar") | |
palindrome?("hello") | |
palindrome?("race car") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment