Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Finding longest palindrome from a string

by japhy (Canon)
on Aug 13, 2004 at 15:55 UTC ( #382732=note: print w/ replies, xml ) Need Help??


in reply to Finding longest palindrome from a string

Because the golf isn't complete without an insanely short regex solution:

sub japhy { # 74 our$P="";pop=~m{(.+).?(??{reverse$1}) (?{length$P<length$&and$P=$&})^}xs;$P }
Update: inspired by ccn's array approach:
sub japhy { # 68 our@P="";pop=~m{(.+).?(??{reverse$ 1})(?{$P[length$&]=$&})^}xs;$P[-1] }
_____________________________________________________
Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart


Comment on Re: Finding longest palindrome from a string
Select or Download Code
Re^2: Finding longest palindrome from a string
by Jasper (Chaplain) on Aug 17, 2004 at 08:45 UTC
    I forgot to mention that one of the golf competitions had a palindrome slant. Terje's perlgolf competitions site. There are some nice solutions there, as usual. Shorter than japhy's! :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://382732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (18)
As of 2014-07-14 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (260 votes), past polls