only works for strings of length 5 or shorter. sort does not use insertion sort for arrays larger than that :-)
#!perl -l
@~=sort{$ARGV[0]!~/$b.*$a/|!$b&&($_.=$b,$b='',-1)}pop=~/./g,z;print
|
the stack approach w/o the stack. long way to go still
#!perl -l
$_=pop;while(/./g){$~=$&;/\G.?/;s|$~||,$o.=$~if$ARGV[0]=~/$&.*$~/}print$o
|
but which 30 characters to drop..
#!perl -l
for($_=pop;s~(.*)\b(\w)~$1~;$}=$2.$}){$z=index$y||=pop,$2;s~.{$z}~$& ~}print$}
|
todo: make this into a regex.. :-)
#!perl -l map$ARGV[0]=~s/(\w*)$_(\w*)/$1~$2/&@o[++$n+length$1.$2]=~s/^/$_/,pop=~/./g;print@o |
brains.. hurt.. on the first try..
#!perl -l
$i=pop;while(@ARGV){$_=pop;s/.//||next;@o=($&,@o);$i=~s/([^~]*)$&/$1~/;
$l=length$1;push@ARGV,/(.{$l})(.*)/}print@o
|