Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
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 lurking in the Monastery: (8)
As of 2014-12-28 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls