Skip to content

Instantly share code, notes, and snippets.

@brandonweiss
Created November 18, 2010 23:33
Show Gist options
  • Save brandonweiss/705888 to your computer and use it in GitHub Desktop.
Save brandonweiss/705888 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
code = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth"
code = code.downcase.split("")
possibilities = []
code.each_with_index do |char, index|
code.each_with_index do |sub_char, sub_index|
next if sub_index < index
code_string = code[index..sub_index].join('')
unless code_string.length == 1
if (char == sub_char) && (code_string == code_string.reverse)
possibilities << code_string
end
end
end
end
puts possibilities.max { |a,b| a.length <=> b.length }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment