in reply to Re: Finding longest palindrome from a string
in thread Finding longest palindrome from a string
return $string . reverse $string;
That only generates even length palindromes. I instead suggest
return ( $string . ( rand < .5 ? $letters[ rand @letters ] : '' ) . reverse $string );
Also, Don't Repeat Yourself. That's far too much copy-paste code there. Look at the benchmark script I wrote: much less code, and it tells you exactly which input strings each solution failed on and what it produced instead.
Makeshifts last the longest.
|
---|
In Section
Seekers of Perl Wisdom