My phone number (which I will not be sharing here) has a neat property where there is a two digit number, which when iteratively removed from my phone number will eventually remove all the digits. For example if my phone number were
abaababbab
Then by repeatedly removing ab
we would eventually get nothing (I encluse the string I am removing in brackets to make it clear)
abaababb[ab]
abaab[ab]b
aba[ab]b
ab[ab]
[ab]
Now to generalize this property lets have any string. A "minimal eraser" of that string will be the smallest substring such that if iteratively removed it will eventually make the string empty.
Some examples at the bottom.
Task and Scoring
Warning: This challenge is not code-golf. Do not assume it is without reading the scoring
Your challenge will be to take a string as input and output a minimal eraser of that string.
Your answers will be scored by taking them as a string of bytes and calculating that string's minimal eraser. The length in bytes of that eraser is your score, with lower being better.
Your answer must support strings containing all printable ascii plus any characters that appear in your program.
Test cases
abaababbab -> ab
baababbab -> baababbab
baababab -> baababab
echoecho -> echo
ototoo -> oto
ibiibibii -> ibi
aabaabaa -> abaa / aaba
aabaabaa
->abaa
oraaba
. \$\endgroup\$_
the ignore-next andn
the no-op. Make an eraser string_n_a_b_c
wherea,b,c
are minimal distinct chars needed. By inserting into itself as_n_a__?_a_b_cb_c
, we can reduce to justb
, and likewise any chars. This lets us make any program be erased by this string. \$\endgroup\$!
as the skip and.
as the noop. \$\endgroup\$ibiibibii
doesn't work if you remove only the last one. It is an eraser if there is any way to do it. \$\endgroup\$