Remove another variable, saving 4 more characters.
#!perl -l
sub z{if(@_>1){my($y,$x)=split/$_[0]/,pop;z(@_[1..length$y],$y).z(@_[1+length$y..$#_],$x).$_[0]}}print z((split//,pop),pop);
|
Remove an extraneous variable by changing the termination setup on the recursion.
#!perl -l
sub z{if(@_>1){my($y,$x,$z)=split/$_[0]/,pop;$z=length$y;z(@_[1..$z],$y).z(@_[$z+1..$#_],$x).$_[0]}}print z((split//,pop),pop);
|
Nuke extraneous variable.
#!perl -l
sub z{my($y,$x,$w,$z)=split/$_[0]/,pop;$z=length$y;$w=z(@_[1..$z],$y)if$z;$w.=z(@_[$z+1..$#_],$x)if$x;$w.$_[0]}print z((split//,pop),pop);
|
All that kvetching about how long 'length' is, and I left an extraneous one in there. Feh.
#!perl -l
sub z{my$z=pop;my($y,$x,$w,$v)=split/$_[0]/,$z;$v=length$y;$w=z(@_[1..$v],$y)if$v;$w.=z(@_[$v+1..$#_],$x)if$x;$w.$_[0]}print z((split//,pop),pop);
|
Things I've learned so far from this: 'return' is optional, as are semicolons immediately in front of }. 'my' really _is_ necessary when you're recursing. Perl likes having a statement between the ':' and ';' in ?: constructs. When working on these problems, 'length' feels like the longest word in the English language.
#!perl -l
sub z{my$z=pop;my($y,$x,$w,$v)=split/$_[0]/,$z;$v=length$y;$w=z(@_[1..$v],$y)if$v;$w.=z(@_[$v+1..$#_],$x)if length$x;$w.$_[0]}print z((split//,pop),pop);
|
First cut. There's got to be a better way to do this, but I don't see it right now.
#!perl -l
sub z{my$z=pop;my($y,$x,$w,$v)=split/$_[0]/,$z;$v=length $y;$w=($v)?z(@_[1..$v],$y):$y;$w.=length($x)?z(@_[$v+1..$#_],$x):$x;return$w.$_[0];}print z((split//,pop),pop);
|