53
4
Challenge
Given a non-empty string S of length L consisting entirely of printable ASCII chars, output another string of length L that consists entirely of printable ASCII chars, but is not equal to S.
For the purposes of this challenge, a printable ASCII char is one between U+0020 and U+007E, inclusive; that is, from
(space) to ~
(tilde). Newlines and tabs are not included.
For example, given "abcde"
, some valid outputs could be:
"11111"
"abcdf"
"edcba"
But these would be invalid:
"abcde"
"bcde"
"abcde0"
Test cases
"asdf"
"1111"
" "
"~~~~~"
"abcba"
"1"
" "
"~"
" ~"
"~ "
" 0"
"!@#$%^&*()ABCDEFGhijklmnop1234567890"
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
Rules
- You may assume the input consists entirely of printable ASCII chars.
- You may not assume that the input does not contain all 95 printable chars.
- You may assume the input contains at least one character and is less than 256 chars long.
- The output must also consist entirely of printable ASCII chars. You could not, for example, output the byte \x7F for input
"~"
. - The output must be different than the input with probability 1; that is, you may generate random strings until one is different than the input, but you can't just output L random characters and hope it's different.
- Newlines are disallowed in the output, but you may output one trailing newline which is not counted toward the string.
Scoring
This is code-golf, so the shortest code in bytes in each language wins.
Note that "positive" excludes the empty string. For extra clarity, maybe replace "positive" with "nonzero"? – CalculatorFeline – 2017-05-30T20:30:21.220
5@CalculatorFeline But that would include negative-length strings /s – ETHproductions – 2017-05-30T20:36:04.070
1...Those don't exist. – CalculatorFeline – 2017-05-30T20:38:07.607
@CalculatorFeline Better now? – ETHproductions – 2017-05-30T20:40:09.867
....really? -_- Also yes. – CalculatorFeline – 2017-05-30T20:40:10.143
Related – TheLethalCoder – 2017-05-31T12:53:18.420
3Another simple but not trivial challenge. – Weijun Zhou – 2018-04-04T15:03:52.190