Got rid of $q; two characters are better than nothing...
#!perl -ln0 s/\G \Q$& / /./ \Q$& /||s/^(\Q$&\E)\s//gm-print$1while/\S+/g;lc&&die |
Handling only one "node node" at a time is enough.
#!perl -ln0 $q="\Q$&",s/\G $q$//m,/ $q /||s/^($q)\s//mg+print$1while/\S+/g;lc&&die |
#!perl -ln0 $q="\Q$&",s/^$q $q$/$q/mg,/ $q /||s/^($q)\s//mg+print$1while/\S+/g;lc&&die |
Using //g is more compact than split.
#!perl -ln0 s/^(.*) \1$/$1/mg;$q="\Q$&",/ $q$/m||s/^($q)\s//mg&&print$1while/\S+/g;$_&&die |
Less than 100!
#!perl -ln01
s/^(.*) \1$/$1/mg;A:while($_){for$k(split){/ \Q$k\E$/m||s/^\Q$k\E\s//mg+print($k)+next
A}die}
|
the tiebreak score helps again.
#!perl -l -034
$_=<>;s/^(.*) \1$/$1/mg;A:while($_){for$k(split){/ \Q$k\E$/m
||s/^\Q$k\E\s//mg+print($k)+next A}die}
|
Hmm, sometimes the tie break score does matter...
#!perl -l -034
($l=<>)=~s/^(.*) \1$/$1/mg;while($l){map+($l!~/ \Q$_\E$/m
and$l=~s/^\Q$_\E\s//mg,print,next),split' ',$l;die}
|
A brand new search-based approach. Can this get me closer to The Amazing Mr. Hospel? >=)
#!perl -ln0
$l=$_;sub X{my$x=$_;$v{$x}++&&return;@r=map$_ eq$x?():X(),$l=~/^(.*) \Q$x\E$/mg;$v{$x}>1&¨@r,$x}print for map X,split
|
#!perl -l
@l=<>;A:while(grep$_,@l){for$k(map split,@l){!grep/ \Q$k\E$/&&!s/^\Q$k\E //,@l
and(map(s/^\Q$k\E\s//,@l),print($k),next A)}die}
|