Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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.

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 contemplating the Monastery: (10)
As of 2016-08-30 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (423 votes). Check out past polls.