Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # -*- ruby -*-
- def palindrome?(palindrome)
- palindrome.strip!
- length = palindrome.size
- return false if length.zero?
- i = 0
- j = length - 1
- while i < j
- while i < j and palindrome[i] == ' '
- i += 1
- end
- while j > i and palindrome[j] == ' '
- j -= 1
- end
- return false if palindrome[i] != palindrome[j]
- i += 1
- j -= 1
- end
- return true
- end
- sentence = gets.chomp
- if (palindrome?(sentence))
- puts "#{sentence} is a palindrome"
- else
- puts "#{sentence} is not a palindrome"
- end
Advertisement
Add Comment
Please, Sign In to add comment