Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Finding longest palindrome from a string

by murugu (Curate)
on Aug 13, 2004 at 09:50 UTC ( [id://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.

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://382593]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found