Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Created January 9, 2012 08:42
Show Gist options
  • Save andreapavoni/1581987 to your computer and use it in GitHub Desktop.
Save andreapavoni/1581987 to your computer and use it in GitHub Desktop.
therubygame palindrome solution
def find_longest_palindrome(string)
(string.size/2).downto(1) do |n|
if m = string.match(Regexp.new("#{'(.)' * (n+1)}?\\#{n.downto(1).to_a.join('\\')}"))
return m
end
end
end
@andreapavoni
Copy link
Author

Argh! thank you for the explanation. For ruby 1.9.x looks like it's a sort of bug (even if I know it's almost weird to use very long regex). I know it's not as fast as other ways, but it was fun to test alternatives ;)

cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment