Skip to content

Instantly share code, notes, and snippets.

@samdalton
Created October 10, 2010 07:03
Show Gist options
  • Select an option

  • Save samdalton/619038 to your computer and use it in GitHub Desktop.

Select an option

Save samdalton/619038 to your computer and use it in GitHub Desktop.
# Q1
input = 'FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth'.downcase!
reverse = input.reverse
length = input.length
longest_word = ""
(0..length).each do |i|
(0..length).each do |j|
if input[i, j] == reverse[length - i - j, j]
if input[i, j].length > longest_word.length
longest_word = input[i, j]
end
end
end
end
p longest_word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment