Skip to content

Instantly share code, notes, and snippets.

@ciniglio
Created December 10, 2012 00:36
Show Gist options
  • Save ciniglio/4247685 to your computer and use it in GitHub Desktop.
Save ciniglio/4247685 to your computer and use it in GitHub Desktop.
Grepline Challenge Pt 1
# Palindrome checker
def palindrome?(s)
a = s.split("")
while a.length > 1 do
return false unless a.pop == a.shift
end
return true
end
# 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