Perl 5 -pl
, 109103 bytes
chomp;@@,=$s=$_;/((.)(?1)\2|(.)(.)\4?\3)?(??{$1?push@,,$`.$':length$s>y!!!c?$s=$_:1;0})/,$_=pop@,while@,;$_=$s
Speed is not great. I'd claim further "-6" from the score -- chomping is only required for the "nice" TIO's many-inputs-in-the-same-screen presentation, not for an input of a single string w/o trailing LF (the same about "-l" switch.)Try it online!
More readable:
chomp;
@, = $s = $_;
/
( (.)(?1)\2 | (.)(.)\4?\3 )?
(??{
$1 ? push @,, $` . $'
: length $s > y!!!c ? $s = $_ : 1;
0
})
/x,
$_ = pop @, while @,;
$_ = $s
Perl 5, (non-competing) 458 bytes
$s = $_;
%seen = ();
while () {
/
(?>^.*?)
(
(
(.)(?-3)\g-1|(.)(.)\g-1?\g-2
)
(?{
$x = substr( $_, 0, $-[2] ) . substr( $_ , $+[2] );
unless ( $seen{ $x } ++ ) {
push @a, $x;
$s = $x if length( $s ) > length( $x )
}
})
)
/x;
last unless @a;
$_ = pop @a
}
$_ = $s;
Short version is terribly inefficient. Just for fun, this is a much faster version (approx. 1 sec for 16 "go"'s in linked TIO's input vs. 9 in the challenge's test case), which hopefully generates correct results.