Given two sets of strings, \$ D \$ and \$ R \$, find the shortest string which contains every string in \$ D \$, but contains none of the strings in \$ R \$.
There are almost always multiple possible outputs; you should output at least one of them, but you can output more.
You can assume this is possible with the inputs you are given; i.e., none of the strings in \$ R \$ are substrings of those in \$ D \$.
Note that the result \$ s \$ may have to include characters which are not present in any of the strings in \$ D \$. For example, when \$ D = \{\text a, \text b\} \$ and \$ R = \{\text {ab}, \text {ba}\} \$, there must be at least one other character in the output - it would have to be something like \$ \text {axb} \$ or \$ \text {bxa} \$.
Furthermore, in order to simplify dealing with the case above, you may choose a character that you can assume to never be present in the input, but is allowed in the output. For example, you may restrict your input to always use letters, but sometimes give outputs containing underscores as well as letters.
"String" here is used in an abstract sense: you may operate on actual strings of characters, but also on lists of positive integers, or any other reasonable domain.
This is code-golf, so the shortest code in bytes wins.
Test cases
\$ D \$ | \$ R \$ | output |
---|---|---|
(empty set) | (empty set) | (empty string) |
(empty set) | a |
(empty string) |
a |
(empty set) | a |
ab , bc |
(empty set) | abc |
a , b |
ab , ba |
axb or a$b or etc. |
ab , bc |
abc |
bcab or abbc |
ab , cd |
bc |
cdab |
ab , a |
c |
ab |
code , golf , fig , egg |
igo |
codeggolfig |
a , b , c |
abc , bac , ca |
cba or acb |
a , b , c |
ab , bc , ac , ba , cb , ca |
a$b$c etc. |
This question came to me while attempting to optimise the substring check in this answer.
a,b,c
andab,ba,ac,ca,bc,cb
->axbxc
oraxb$c
or etc. (2 filler-characters required) \$\endgroup\$