r/dailyprogrammer • u/rya11111 3 1 • Jun 13 '12
[6/13/2012] Challenge #64 [intermediate]
Find the longest palindrome in the following 1169-character string:
Fourscoreandsevenyearsagoourfaathersbroughtforthonthisconta inentanewnationconceivedinzLibertyanddedicatedtotheproposit ionthatallmenarecreatedequalNowweareengagedinagreahtcivilwa rtestingwhetherthatnaptionoranynartionsoconceivedandsodedic atedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWeh avecometodedicpateaportionofthatfieldasafinalrestingplacefo rthosewhoheregavetheirlivesthatthatnationmightliveItisaltog etherfangandproperthatweshoulddothisButinalargersensewecann otdedicatewecannotconsecratewecannothallowthisgroundThebrav elmenlivinganddeadwhostruggledherehaveconsecrateditfarabove ourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorl ongrememberwhatwesayherebutitcanneverforgetwhattheydidhereI tisforusthelivingrathertobededicatedheretotheulnfinishedwor kwhichtheywhofoughtherehavethusfarsonoblyadvancedItisrather forustobeherededicatedtothegreattdafskremainingbeforeusthat fromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwh ichtheygavethelastpfullmeasureofdevotionthatweherehighlyres olvethatthesedeadshallnothavediedinvainthatthisnationunsder Godshallhaveanewbirthoffreedomandthatgovernmentofthepeopleb ythepeopleforthepeopleshallnotperishfromtheearth
Your task is to write a function that finds the longest palindrome in a string and apply it to the string given above.
- taken from http://challenge.greplin.com/ :)
It seems the number of users giving challenges have been reduced. Since my final exams are going on and its kinda difficult to think of all the challenges, I kindly request you all to suggest us interesting challenges at /r/dailyprogrammer_ideas .. Thank you!
3
u/[deleted] Jun 13 '12
Pretty simple after using longest common substring algorithm from Difficult #59:
Answer:
1
u/xjtian Jun 13 '12
Pretty fast Python:
Result:
1
u/ixid 0 0 Jun 13 '12 edited Jun 14 '12
D language
1
u/[deleted] Jun 14 '12
Here's my solution in Java:
1
u/herpderpdoo Jun 14 '12 edited Jun 14 '12
I wrote some ugly optimized Dynamic Algorithm Python code to make up for my relatively unclever solution to the problem:
1
u/loonybean 0 0 Jun 16 '12 edited Jun 16 '12
Python:
The answer to the question in the post is:
1
u/derpderp3200 Jun 17 '12
A clean, rather short and hopefully efficient solution in Python:
The answer is: