46
3
Given two strings, output a third string that is not equal to either of the two inputs, but has the same length (in characters) as either of the inputs. There is guaranteed to be at least one valid output.
Test Cases
Test cases are quoted to show they are strings. Outputs are one of many possible.
input, input -> output
"test", "test" -> "tttt"
"do", "don't" -> "dnut_"
"ye s", "yes" -> "fals"
"yes", "yes" -> "noo"
"maybe", "mayue" -> "false"
"false", "false" -> "truee"
"false", "true" -> "fatr"
"1", "" -> "0"
"", "t" -> "s"
"", "abcabc" -> "testst"
"abcdefghijklmnopqrstuvwxyz", "aaaaaaaaaaaaaaaaaaaaaaaaaa" -> "zbcdefghijklmnopqrstuvwxya"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" -> "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
Rules
- You may chose your input domain, but it must be composed of at least printable ASCII, and your output domain must be the same as your input domain.
- The input lengths may be the same or different.
- The output must be valid with probability 1; that is, you may generate random strings until one is valid (and theoretically you might infinite loop), but you can't just output a random string and hope it's valid. Note that this means you output does not need to be deterministic.
- Automatic trailing newlines allowed, but they do not count towards the length of the output.
- Due to questions regarding Memory Errors, it must work within 60 seconds up to input lengths of
6
. An answer that works for that and theoretically works for longer strings is OK, but something that Memory Errors on modern computer for input length4
is not valid.
This is code-golf, so shortest answer in bytes wins.
Related, Sandbox – Stephen – 2017-08-18T22:08:54.970
Can my code fail for MaxChar in input, but be able to output it? – H.PWiz – 2017-08-18T22:27:33.540
@H.PWiz no. if it can be outputted, it has to be able to be inputted, otherwise you could just do
MaxChar.repeat(s1.length)
– Stephen – 2017-08-18T22:28:25.563That makes sense – H.PWiz – 2017-08-18T22:28:50.413
14This seems like another of an interesting new category of questions on this site that are easy for humans and hard for computers. Because computers aren't good at divergent thinking! It reminds me of the Spongebob episode where he's up all night trying to write an essay on what NOT to do at a stoplight. – geokavel – 2017-08-18T22:47:34.670
Test case:
abcdefghijklmnopqrstuvwxyz
andaaaaaaaaaaaaaaaaaaaaaaaaaa
. Mine failed for it – Mr. Xcoder – 2017-08-18T23:11:55.0932I understand the output domain can be a subset of the input domain, yes? – Luis Mendo – 2017-08-18T23:21:58.320
@LuisMendo yes. – Stephen – 2017-08-18T23:25:09.620
1Will the two inputs ever both be an empty string? – kamoroso94 – 2017-08-19T15:53:28.393
1@kamoroso94 no, because there is guaranteed to be a valid output. – Stephen – 2017-08-19T18:28:07.407
2Nice question! I like it. – isaacg – 2017-08-20T22:16:58.287
For
"1", ""
may we output""
? – Quelklef – 2017-08-21T02:55:10.1602@Quelklef No, that's not different from both inputs. – Ørjan Johansen – 2017-08-21T02:58:08.297
@ØrjanJohansen Of course. Thanks. – Quelklef – 2017-08-21T03:02:47.087
3I suggest "", "1" should be added as a test case, since I just realized my answer fails for this even though it works for all the provided test cases – Slow loris – 2017-08-22T23:20:50.810
I'm pretty sure the point of @Slowloris 's request was to have the empty string as the first one. – Ørjan Johansen – 2017-08-23T01:04:21.590
Suggested test case: both input strings are longer than 256 characters. – DLosc – 2019-03-26T02:17:40.613
@DLosc added, thanks – Stephen – 2019-03-26T02:27:13.003