Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Finding longest palindrome from a string

by BrowserUk (Pope)
on Aug 13, 2004 at 12:57 UTC ( #382644=note: print w/replies, xml ) Need Help??


in reply to Finding longest palindrome from a string

#! perl -slw use strict; sub buk { my $string = shift; my @pals; while( $string =~ m[(.) (?=( (?:\1) | (?:.\1) ) ) ]gx ){ my( $left, $right ) = ( $-[ 0 ], $+[ -1 ] ); while( $left and $right < length( $string ) and substr( $string, $left, 1 ) eq substr( $string, $right, 1 +) ) { $left--; $right++ ; } my $pal = substr( $string, $left, $right - $left ); if( !@pals or length( $pals[ -1 ] ) < length( $pal ) ) { @pals = $pal; } else { push @pals, $pal unless @pals; } } return wantarray ? $pals[ 0 ] : @pals; } print $ARGV[ 0 ]; print ' ' x index( $ARGV[ 0 ], $_ ), $_ for buk $ARGV[ 0 ]; __END__ P:\test>382567 1111111121111111111112111111111111111111111112111111111 +111211111 1111111121111111111112111111111111111111111112111111111111211111 11111121111111111112111111111111111111111112111111111111211111 P:\test>382567 1111111121111111111112111111111111111111111112111111111 +1121111 11111111211111111111121111111111111111111111121111111111121111 111111111111211111111111111111111111211111111111


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://382644]
help
Chatterbox?
[Discipulus]: LA something a little more perlish? @mts = map {qx!mp3info -p $_!} glob '/path/*.mp3 (hazarded code)
[Discipulus]: many monks want to be hired tonight, other haired and some aired
[Lady_Aleena]: Discipulus, do glob recurse?
[Lady_Aleena]: s/do/does/;
LanX wants to be fired
[Discipulus]: i fear no
[Discipulus]: i invented also 'gired'
[Lady_Aleena]: Discipulus, then that is a problem. I wanted to find total seconds of my entire .mp3 collection to do some math on it to see how many days of continuous music i have.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-04-23 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.