Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Finding longest palindrome from a string

by murugu (Curate)
on Aug 13, 2004 at 09:50 UTC ( #382593=note: print w/ replies, xml ) Need Help??


in reply to Finding longest palindrome from a string

here is my code:
sub palindrome{ my $x=shift; my $prev=0; while ($x=~/(([a-z0-9]+)[a-z0-9]?(??{reverse $2}))/gi) { $max=$1 if (length($1)>$prev); $prev=length $max; } $max }

update:

Sorry monks i haven't read the question carefully, left out space condition itself.


Comment on Re: Finding longest palindrome from a string
Download Code
Replies are listed 'Best First'.
Re^2: Finding longest palindrome from a string
by ccn (Vicar) on Aug 13, 2004 at 10:07 UTC

    Your code doesn't work with 'ababbab'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2015-07-30 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls