note
Aristotle
<blockquote><code>
return $string . reverse $string;
</code></blockquote>
<p>That only generates even length palindromes. I instead suggest</p>
<code>
return (
$string
. ( rand < .5 ? $letters[ rand @letters ] : '' )
. reverse $string
);
</code>
<p>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.</p>
<div class="pmsig pmsig-114691">
<p align="right"><em>Makeshifts last the longest.</em></p>
</div>
382567
383423