14
Given (on STDIN, as command line arguments, or as function arguments) two distinct non-empty strings, find and return the shortest substring of the first string which is not a substring of the second. If no such substring exists, you may return the empty string, return any string which isn't a substring of the original string, or throw an exception. If you are returning from a function, you may also return null (or undefined, None, etc.) in this case. If multiple such substrings are tied for the shortest, you may return any one of them.
Strings can consist of any printable ascii characters.
Input given on STDIN will be given with one string on each line. At your request, a single empty line may be added at the end of the input.
This is code golf, so the shortest valid program wins.
SOME TEST CASES
INPUT:
STRING ONE
STRING TWO
OUTPUT:
E
INPUT:
A&&C
A&$C
VALID OUTPUTS:
&&
&C
INPUT:
(Two randomly-generated 80-letter strings)
QIJYXPYWIWESWBRFWUHEERVQFJROYIXNKPKVDDFFZBUNBRZVUEYKLURBJCZJYMINCZNQEYKRADRYSWMH
HAXUDFLYFSLABUCXUWNHPSGQUXMQUIQYRWVIXGNKJGYUTWMLLPRIZDRLFXWKXOBOOEFESKNCUIFHNLFE
ALL VALID OUTPUTS:
AD
BJ
BR
CZ
DD
EE
ER
EY
EY
FF
FJ
FW
FZ
HE
IJ
IN
IW
JC
JR
JY
KL
KP
KR
KV
LU
MH
MI
NB
NQ
OY
PK
PY
QE
QF
QI
RA
RB
RF
RO
RV
RY
RZ
SW
UE
UH
UN
UR
VD
VQ
VU
WB
WE
WI
WU
XN
XP
YI
YK
YK
YM
YS
YW
YX
ZB
ZJ
ZN
ZV
1shortest or longest? – Leaky Nun – 2016-04-29T15:12:49.077
@FryAmTheEggman Then should I still post my solution... – Leaky Nun – 2016-04-29T15:15:04.327
"One string on each line" with or without quotes? – Leaky Nun – 2016-04-29T15:21:50.610
1Can we take an array of strings? – Dennis – 2016-04-29T17:16:57.963
is "B" a substring of "aBc" ? – downrep_nation – 2016-04-29T17:58:21.793
Can we return something else than a string (0, None, undefined, etc.) if there is no unique substring? – Dennis – 2016-04-29T18:50:33.050
@downrep_nation ...yes. – SuperJedi224 – 2016-04-29T19:12:53.480
so any non empty character string2 doesnt contain is fine... i see
please add test cases tho – downrep_nation – 2016-04-29T19:14:36.007
-1 for lack of test cases. – cat – 2016-04-30T15:32:51.817