http://qs1969.pair.com?node_id=77415


in reply to (Golf) Fragment Reassembly

This is a really cool problem! ++, MeowChow.

sub assemble { $x='';sub a{($p,$q)=@_;return$q if!$p;$l=length$p;for(0..$l){$y= substr($p,0,$_).$q;return$y if substr($y,0,$l)eq$p}}sub b{my$s;$s=a( $s,$_)for@_;$x=$s if!$x||length$s<length$x;} sub c{my($a,$b)=@_;if(@$b){for(0..$#$b){my@c=@$b; c([@$a,splice@c,$_,1],[@c])}}else{b @$a}}c([],[@_]);$x }

279 by my count. I know I could cut this down further in the recursion, but I'm damned if I can see it right now.