#!perl -ln0 / \Q$&/||print$1while s/( |(?= ?\G))\Q$&/ /g,/(\S+) /g/$#+ |
the dual solution
#!perl -ln0 /(?<= )\Q$& /||print$1while s/( |\G)\Q$&/ /g,/(\S+) /g/$#+ |
#!perl -ln0 / \Q$&\E$/m||print$&while s/(^|\G)\Q$&\E\s/ /mg,/\S+/g;1/!// |
Do everything with one statement A pity I needed to add that () But maybe distinguishing $1 and $& will prove useful
#!perl -ln0 / \Q$&\E$/m||print$&while s/(^|\G)\Q$&\E\s/ /mg,/(\S+)/g/$#+ |
fails if the same singleton can appear multiple times in the input. Needs rule clarification
#!perl -ln0 /(?!\G) \Q$& /||print($&)+s/^(\Q$&\E\s)+/ /mgwhile/\S+/g;1/!// |
#!perl -ln0 s/\G \Q$& / /+/ \Q$& /||print$&while s/^\Q$&\E\s//mg,/\S+/g;1/!// |
#!perl -ln0 s/\G \Q$& / /-/ \Q$& /||print($&)+s/^\Q$&\E\s//mgwhile/\S+/g;1/!// |
#!perl -p0 s/\G \Q$& / /+/ \Q$& / or$\.="$& ",s/^\Q$&\E\s//mgwhile/\S+/g;1/!// |
#!perl -ln0 s/\G \Q$& / /+/ \Q$& /||print($&)+s/^\Q$&\E\s/ /mgwhile/\S+/g;1/!// |
#!perl -ln0 s/\G \Q$& / /+/ \Q$& /||print($&)+s/^\Q$&\E\s/\n/mgwhile/\S+/g;1/!// |
#!perl -ln0 /^(.+) (?!\1 )\Q$& /m||print($&)+s/^(\Q$&\E\s)+/ /mgwhile/\S+/g;1/!// |
#!perl -ln0 /^(?!\Q$&\E ).* \Q$& /m||print($&)+s/^(\Q$&\E\s)+/ /mgwhile/\S+/g;1/!// |
This shows a problem with the test program
#!perl -Xln0 /^(?!\Q$&\E ).* \Q$& /m||print$&|s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;exit// |
#!perl -ln0 /^(?!\Q$&\E ).* \Q$& /m||print($&)+s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;1/!// |
#!perl -Xln0 /^(?!\Q$&\E ).* \Q$& /m||print($&)+s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;exit// |
#!perl -Xln0 /^(?!\Q$&\E ).* \Q$& /m||print"$&"|!s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;exit// |
#!perl -Xln0 /^(?!\Q$&\E ).* \Q$& /m||print"$&",!s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;exit// |
#!perl -Xln0 /^(?!(\Q$&\E) ).* \Q$& /m||print"$&"|!s/^(\Q$&\E\s)+/ /mgwhile/^\S+/gm;exit// |
#!perl -Xln0 $;=$&and/^(?!\Q$;\E ).* \Q$; /m||s/^(\Q$;\E\s)+/ /mg*print$;while/^\S+/gm;exit// |
#!perl -Xln0 $;=$+and/^(?!\Q$;\E ).* \Q$; /m||s/^(\Q$;\E\s)+/ /mg*print$;while/^(\S+)/gm;exit// |
#!perl -ln0
$;=$+and/^(?!\Q$;\E ).* \Q$;
/m||s/^(\Q$;\E\s)+/
/mg*print$;while/^(\S+)/gm;//&&die}{
|
#!perl -ln0
$;=$+and/^(?!\Q$;\E ).* \Q$;
/m||s/^(\Q$;\E\s)+/
/mg*print$;while/^(\S+)/gm;/./&&die}{
|
#!perl -ln0
$;=$+and/ \Q$;
/||s/^\Q$;\E\s/
/mg*print$;while/^(\S+)/gm;print$+while s/^(\S+) \1$//m;/./&&die}{
|
#!perl -ln0
$;=$+and/ \Q$;
/||s/^ ?\Q$;\E\s/
/mg*print$;while/^(\S+)/gm;print$+while s/^(\S+) \1$//m;/./&&die}{
|