<?xml version="1.0" encoding="windows-1252"?>
<node id="77591" title="Re: (Golf) Fragment Reassembly" created="2001-05-03 06:55:57" updated="2005-07-19 14:08:39">
<type id="11">
note</type>
<author id="17251">
MeowChow</author>
<data>
<field name="doctext">
Ok, here's my current solution at 192 chars.
&lt;code&gt;
sub a{$#_?(sort{length$a&lt;=&gt;length$b}map{my$s=$_;my@l=grep{$s ne $_}@_;map{my$t=$_;my@m=grep{$t ne $_}@l;a(i($s,$t),@m)}@l}@_)[0]:pop}
sub i{($_,$t)=@_;chop$t while!s/\Q$t\E$/$_[1]/&amp;&amp;''ne$t;$_;}

print a qw(logger gerbil log analog);
print "\n";
print a qw(GATTACA ATTACA GATT AAGAT CCC);
&lt;/code&gt;
&lt;b&gt;update1&lt;/b&gt;: trimmed another 4 chars from the &lt;code&gt;i&lt;/code&gt; sub, and stopped clobbering globals:
&lt;code&gt;
sub i{my($s,$t)=@_;chop$t while$s!~s/\Q$t\E$/$_[1]/;$s}
&lt;/code&gt;
... if we're clobbering $_, we can trim another 5:
&lt;code&gt;
sub i{($_,$t)=@_;chop$t while!s/\Q$t\E$/$_[1]/;$_}
&lt;/code&gt;
&lt;b&gt;update2&lt;/b&gt;: 163 chars, strict and global-clean, all in one sub, named &lt;code&gt;assemble&lt;/code&gt; (or 156 if it's named &lt;code&gt;a&lt;/code&gt;):
&lt;code&gt;
sub assemble{$#_?(sort{length$a&lt;=&gt;length$b}map{my$s=$_;my@l=grep$s ne$_,@_;map{my($t,$u)=($s,$_);my@m=grep$u ne$_,@l;chop$u while$t!~s/\Q$u\E$/$_/;assemble($t,@m)}@l}@_)[0]:pop}
&lt;/code&gt;
&lt;pre&gt;
  &lt;a href="/index.pl?node=MeowChow"&gt; MeowChow                                   &lt;/a&gt;
               s aamecha.s a..a\u$&amp;owag.print&lt;/pre&gt;</field>
<field name="root_node">
77183</field>
<field name="parent_node">
77183</field>
</data>
</node>
