Skip to content

Instantly share code, notes, and snippets.

@rickmzp
Created September 5, 2012 00:53
Show Gist options
  • Save rickmzp/3628642 to your computer and use it in GitHub Desktop.
Save rickmzp/3628642 to your computer and use it in GitHub Desktop.
@data = open("gettysburg.txt").read
@longest_palindrome = ""
@position = 0
def regex
/#{@data[@position, @longest_palindrome.length + 1].reverse}/
end
while (@position + @longest_palindrome.length + 1) < @data.length
while match = @data.match(regex)
@longest_palindrome = match[0].reverse
puts @longest_palindrome
end
@position += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment