<?xml version="1.0" encoding="windows-1252"?>
<node id="383581" title="Re^2: Finding longest palindrome from a string" created="2004-08-17 04:17:08" updated="2005-07-03 18:18:43">
<type id="11">
note</type>
<author id="114691">
Aristotle</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;code&gt;
return $string . reverse $string;
&lt;/code&gt;&lt;/blockquote&gt;

&lt;p&gt;That only generates even length palindromes. I instead suggest&lt;/p&gt;

&lt;code&gt;
return (
    $string
    . ( rand &lt; .5 ? $letters[ rand @letters ] : '' )
    . reverse $string
);
&lt;/code&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;div class="pmsig pmsig-114691"&gt;
&lt;p align="right"&gt;&lt;em&gt;Makeshifts last the longest.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;</field>
<field name="root_node">
382567</field>
<field name="parent_node">
383423</field>
</data>
</node>
