Created
December 10, 2012 00:36
-
-
Save ciniglio/4247685 to your computer and use it in GitHub Desktop.
Grepline Challenge Pt 1
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
# Palindrome checker | |
def palindrome?(s) | |
a = s.split("") | |
while a.length > 1 do | |
return false unless a.pop == a.shift | |
end | |
return true | |
end |
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
# Slightly more efficient way to get all substrings | |
def potential_palindrome_substrings(s) | |
s.downcase! | |
a = [] | |
(0...s.length).each do |i| | |
j = i+1 | |
while(s.index(s[i],j)) do | |
j = s.index(s[i],j) + 1 | |
a << s[i..s.index(s[i],j-1)] | |
end | |
end | |
return a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment