g | x | w | all
Bytes Lang Time Link
122SAKO250327T161620ZAcrimori
039Swift 6250302T003237ZmacOSist
055Tcl181226T204434Zsergiol
nanPxem240618T135713Z鳴神裁四点一号
nan230611T030811ZDadsdy
001Thunno 2 JB230610T161846ZThe Thon
004MathGolf230308T095752ZKevin Cr
008APL Dyalog Extended230302T131904ZThe Thon
nan230302T132513ZThe Thon
003Vyxal220105T232837Zemanresu
006Husk201118T103452ZDominic
036naz200907T071918Zsporebal
011MAWP200819T072752ZRazetime
026PowerShell181227T234037ZVeskah
025SmileBASIC180404T235408Z12Me21
022C gcc180412T044505ZMegaTom
026Python 3180404T074859Zxbarbie
003><>171230T012224ZJo King
040R180405T074744ZSean Rob
006Gol><>180406T171849ZBubbler
002str180404T233322ZConor O&
009Pyth180404T151759Zuser4854
014Perl 6180404T135142ZPhil H
042BrainFlak180404T111242ZJo King
068Swift 3180403T164909Zuser3151
012Pyth180403T225632Zhakr14
071SNOBOL4 CSNOBOL4180403T192434ZGiuseppe
077Fortran GFortran180403T190340Zrafa1111
038Java 8180403T091521ZKevin Cr
026Julia 0.6180111T000323Zgggg
nanPerl 5180110T232311ZXcali
001Pushy171226T123558ZFlipTack
006x86 opcode171230T083420Zl4m2
027brainfuck171226T155327ZJo King
047BrainFuck171226T145041Zl4m2
029C/C++171226T133953ZHatsuPoi
008Charcoal170531T085713ZNeil
022Funky171121T025144ZATaco
014Implicit170906T003843ZMD XF
003Golfscript170906T015526ZJosiah W
049Perl 5170820T231103ZEd.
023Cubically170809T233203ZTehPers
045TSQL170623T165529ZBradC
019x86 Assembly170623T155523ZGovind P
034SAS170602T103855Zuser3490
025Python 2170530T160733Zxnor
005Chip170531T195509ZPhlarx
031PHP<7.1170530T165400ZJör
046C#170531T111502ZLiefdeWe
020C gcc170531T104230ZØrj
012Braingolf170531T100057ZMayube
009Brachylog170531T065336ZFatalize
009Alice170531T014850ZNitrodon
022C gcc170530T224625ZDennis
nanRuby170530T222811ZValue In
010Cubix170530T215413ZETHprodu
019JavaScript ES6170530T161556ZStephen
027PHP170530T204150ZChristop
004Japt170530T201206ZOliver
007V170530T170922ZDJMcMayh
011><>170530T185847ZLuis Men
024JavaScript ES6170530T190814ZNeil
009Aceto170530T183213ZL3viatha
019Haskell170530T182827ZØrj
004Convex170530T181308ZGamrCorp
003Jelly170530T172832ZDennis
021Python 2170530T170906Zxnor
013Bash + coreutils170530T173540ZDigital
00305AB1E170530T173414ZRiley
004Jelly170530T165921ZDennis
nan170530T170349ZBrad Gil
005MATL170530T161626ZLuis Men
020Haskell170530T161518Zxnor
059Whitespace170530T163155ZCensored
006Retina170530T160100Zuser4180
005CJam170530T161641ZMartin E
018Octave170530T160602ZStewie G
053BrainFlak170530T161411ZRiley
026Haskell170530T160720Znimi
00505AB1E170530T160324ZEmigna

SAKO, 122 bytes

PODPROGRAM:F(*T)
CALKOWITE:*T,I
STRUKTURA(2*8):T
I=0
1)T(I)=MOD(T(I),9)+2
I=I+1
GDYT(I)=0:2,INACZEJ1
2)DRUKUJWIERSZ:T
WROC

Works in KW6 encoding, but shouldn't largely matter.
Explanation: We loop through every element in the array taking modulo of it and 9. Later we add 2 to not have a 0.
We stop when we find 0 as it symbolizes the end of the string (we may know that, because we assume that the string is less than 256 characters long, which is how large is our array.

Full programme version, 131 bytes

CALKOWITE:*T,I
BLOK(2*8):T
T(=I)=0
CZYTAJWIERSZ:T
I=0
1)T(I)=MOD(T(I),9)+2
I=I+1
GDYT(I)=0:2,INACZEJ1
2)DRUKUJWIERSZ:T
STOP1
KONIEC

Swift 6, 39 bytes

{String(($0+"").map{$0=="#" ?"@":"#"})}

This is fairly trivial. For each character in $0, we return "@" if it's a hash, or "#" otherwise. (You could replace those with any two distinct characters, I just had Swift macros on my mind while writing this.)

Tcl, 55 bytes

proc C s {join [lmap x [split $s ""] {expr {$x<1}}] ""}

Try it online!

Approach very similar to last one: replaces some characters different from one by one, and some other characters different from zero by zero.


# [Tcl], 56 bytes
proc C s {join [lmap x [split $s ""] {expr {$x==0}}] ""}

Try it online!

Approach very similar to last one: replaces every non-zero by a zero and every zero by one.


# [Tcl], 62 bytes
proc C s {puts [expr {[string in $s 0]==0}][string ra $s 1 e]}

Try it online!

Approach replaces first character by 1 if it is a 0, else it replaces anything else by a 0.

--- # [Tcl], 83 bytes
proc C s {scan [string in $s 0] %c f
puts "[format %c [incr f]][string ra $s 1 e]"}

Try it online!

Pxem, 27 + 0 = 27 bytes

Filename (\1 is a codepoint 1)

.w.i.c}.x.s!! .a.c\1.+.a.-.p

Content

Try it online! with RPxem.

How it works

.w                    .a

Loop while stack is empty or (1) pop a value. Then (2) the value is nonzero.

  .i

Read a character. EOF is -1.

    .c}.x.s!! .a

If the character is greater than codepoint of } (~ is the only one) replace it with . !! is to get out of the loop between .x and .a.

.w              .c\1.+.a

Get out of the loop when EOF is received; dup, push 1, add. Loop while nonzero.

                        .-.p

Pop two values to push its difference; which is last non-eof minus -1. Finally output every stack character.

Tldr: reverse entire input. The final character is incremented. However every occurrence of tilde ~ is replaced with ; but last ~ is with !.

Future direction

(,) N, 116 108 Chars or \$108\log_{256}(3)\approx21.4\$ Bytes

((),()()()()()()())(,,,,(()(),((()()())))(()(),(),(),,(()()),()((),,,,(),,(())))(()(),(),()(),,(()()),()()))

Try It Online!
Or, without flags, for 138 chars or 27.34 Bytes

((),()()()()()()()()()())(,,,,(()(),((()()())))(()(),(),,(())(())(())()(),(()()),(())(())(())(()))(()(),(),,(())(())(())(()),(()()),()()))

Try It Online!
Basically, it outputs 1 (with flags) or \32 (without flags) if the char code is greater than or equal to that of \50 (with flags) or \40 (without flags), and outputs 2 (with flags) or \40 (without flags) otherwise.
The reason 1 and 2 are written as 1 and 2 rather than as \49 and \50 is because they are outputted numerically, hence the need for the N flag to remove seperators. All others are encoded in the code by char code.

Thunno 2 JB, 1 byte

E

Attempt This Online!

Thunno 2, 3 bytes

CEJ

Attempt This Online!

Port of Riley's 05AB1E answer. Converts to charcodes and checks if even. Then, joins the resulting list.

MathGolf, 4 bytes

É1░¡

Converts 1 to 0 and every other character to 1.

Try it online.

Explanation:

É     # Foreach over each character of the (implicit) input-string,
      # using 3 characters as inner code-block:
 1░   #  Push 1, and convert it to a string: "1"
   ¡  #  Check whether it's NOT equal to the current character
      # (after which the entire stack is joined together and output implicitly)

APL (Dyalog Extended), 11 8 bytes

∊⍕¨'0'=⎕

Try it online!

-3 thanks to @Adám

Explanation

∊⍕¨'0'=⎕
   '0'=⎕        For each character: 1 if it's '0', 0 otherwise
 ⍕¨             Convert each to string
∊               Flatten into a single string

Thunno J, \$ 5 \log_{256}(96) \approx \$ 4.12 bytes

O2%1_

Attempt This Online!

Port of Riley's 05AB1E answer.

Explanation

O2%1_  # Implicit input
O      # Ordinals of input
 2%    # Mod 2 (vectorised)
   1_  # Not (vectorised)
       # J flag joins the list
       # Implicit output

Vyxal, 3 bytes

C∷ṅ

Try it Online!

05AB1E port, go read that.

Husk, 6 bytes

ṁ(s%5c

Try it online!

Port of Jo King's answer - upvote it!
Outputs ASCII values MOD 5.

naz, 36 bytes

2a2x1v1x1f1r3x1v2e5p1o1f0x1x2f0a0x1f

Works for any input string terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v             # Set variable 1 equal to 2
1x1f               # Function 1
    1r             # Read a byte of input
      3x1v2e       # Jump to function 2 if it equals variable 1
            5p1o   # Otherwise, output it modulo 5
                1f # Jump back to the start of function 1
1x2f               # Function 2
    0a             # Add 0 to the register
1f                 # Call function 1

MAWP, 11 bytes

0|[!5P5WA:]

Idea from Jo King's answer.

Prints the ASCII value of each letter modulo 5.

Try it!

PowerShell, 37 26 bytes

Thanks Mazzy for -11 bytes

-join($args|% t*y|%{$_%9})

Try it online!

Does alright. Uses the ToCharArray trick to save some bytes. Through a conversion chain, mods the ASCII value of each character by 9 then joins up the value.

SmileBASIC, 27 25 bytes

DEF D S
S[0]=@1[S>"2"]END

Creates a function named D that is called like:

STRING$="abcde"
D STRING$
'STRING$ is now "1bcde"

The first character is replaced with either @ or 1

C (gcc), 22 bytes

f(char*s){*s=~1&*s^2;}

Try it online!

Python 3, 29 26 bytes

lambda s:'a~'[s<'~']+s[1:]

Try it online!

><>, 9 3 bytes

5%n

Try it online!

Takes input through the -s flag. Mods each digit with 5 and prints the integer, ending when the stack is empty. This results in only 5 possible output characters, 0-4. Each of those numbers when inputted will produce themselves plus 3, as the ASCII value of 0 is 48, which mod 5 is 3. While the output is reversed, no number is equivalent to another.

Both 7, 9 and a(10) also work as they are not factors of 48 and print single digits.

R, 40 bytes

function(s)substr(shQuote(s),1,nchar(s))

This uses the shell quoting function shQuote to place appropriate quotes around a string and escape quotes within the string (similar to @xnor's answer). Then take a substring that's as long as the original string (because the string might have multiple escaped characters, we need to take a substring of the correct length, so we can't just use substring(...,3)). sQuote is shorter, but converts to ‘‘’.

Another approach, using more 'core' R stuff is 46 bytes:

function(s)sub(".",letters[grepl("^a",s)+1],s)

Substitute the first character with 'a', unless it is 'a', then substitute it for 'b'. sub only substitutes the first match, so we don't need ^. letters is constant and a slightly shorter way of doing c("a","b"). grepl returns a boolean, and adding 1 converts it to a number that indexes letters. The ^ is needed to correctly convert "ba".

Code to test

x = function(s)substr(shQuote(s),1,nchar(s))

test = function(t){
  t2 = x(t)
  t2!=t & nchar(t)==nchar(t2)
}

testStrings = c("a","b","ab","ba","aa",
                "'","'\"","\\\\",'"','""',
                '‘','’',"~","asdf",
                "1111","       ","~~~~~","abcba",
                "1"," ","~"," ~","~ ","  0",
                "!@#$%^&*()ABCDEFGhijklmnop1234567890",
                " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~")

all(sapply(testStrings,test))

Gol><>, 6 bytes

iE;5%n

Try it online!

Direct translation of Jo King's ><> answer.

str, 2 bytes

XV

Try it online!

Explanation

XV
       over each character:
X         increment it  ("~" becomes "\x7f" and "@" becomes "A")
 V        wrap to printable ascii ("\x7f" becomes " ")

Alternatively, YV to decrement instead of increment.

Pyth, 9 bytes

*h-+QGhQl

Try it here

Explanation

*h-+QGhQl
   +QG      Stick the alphabet to the end of the input.
  -   hQ    Delete all instances of the first character.
 h          Take the first remaining character.
*       lQ  Multiply by the length of the (implicit) input.

Perl 6, 14 bytes

{.ord%7~.chop}

Try it online!

Bare block, implicit lambda with input $_. The ordinal of the first character .ord modulo 7 is a different character: Non-numeric first character becomes numeric, numeric first characters map to a different character. If we append the input sans the last character (~ $_.chop), we match the length. It can never match the input because the first character never matches.

Perl 6, 15 bytes

{S/./{.ord%7}/}

Performs S/// substitution (which returns the result of substituting on $_), matching . (any character) once, and replacing it with the ordinal of the first character in $_ - the same character - modulo 7. Non-numeric first character becomes numeric, numeric first characters map to a different character.

Try it online!

Brain-Flak, 42 bytes

({}[((((()()()()){}){}){})]<>){{}}([]<>{})

Try it online!

Replaces the first character of the string with a space, or a ! if the first character is already a space.

Swift 3, 76 68 bytes

let s=readLine()!;print(s.characters.map{$0=="a" ?"b":"a"}.joined())

Try it online!

Pyth, 12 bytes

+C+%ChQlG32t

Test suite

Python 3 translation:
Q=eval(input())
print(chr(ord(Q[0])%26+32)+Q[1:])

SNOBOL4 (CSNOBOL4), 71 bytes

	INPUT LEN(1) . X REM . S
	X =IDENT(X) 1	:S(O)
	X =0
O	OUTPUT =X S
END	

Try it online!

Replaces the first character of S with a 0 unless it's already, 0 in which case it swaps it with 1.

Fortran (GFortran), 77 bytes

CHARACTER(256)A
READ*,A
A(1:1)=CHAR(MOD(IACHAR(A(1:1))+1,94)+33)
PRINT*,A
END

Try it online!

It does what was required... well, with some issues...

1) If the first character is "or <space>, they will be ignored;

2) If there is /, it will be understood as something like "end of transmission";

3) There will be a leading space (which is not part of the output (so do I think), because Fortran always prints a leading space if the output is not formated) and up to 255 trailing spaces. This last problem (i.e., the trailing spaces) can be solved using no more then six bytes.

Java 8, 39 38 bytes

s->(s.charAt(0)<49?9:0)+s.substring(1)

Try it online.

Explanation:

If the first character has a unicode value below 49 (space, or one of !"#$%&'()*+'-./0), change it to a '9', else change it to a '0'.

s->                 // Method with String as both parameter and return-type
  (s.charAt(0)<49?  //  If the first character has a unicode value below 49:
    9               //   Change the first character to a '9'
  :                 //  Else
   0)               //   Change the first character to a '0'
  +s.substring(1)   //  And return the rest of the input-String (if any)

Julia 0.6, 26 bytes

s->map(x->x<'b'?'b':'a',s)

Try it online!

Perl 5, 23 + 1 (-p) = 24 bytes

s/./chr 65+ord($&)%26/e

Try it online!

Blatantly steals @FlipTack's method to change the first character to a different upper case letter.

Pushy, 1 byte

Q

Try it online!

This converts the given string into list of ASCII character codes, indexes them (modular indexing) into the uppercase alphabet, then prints the result. Essentially, each character n is mapped to chr(ord(n) % 26 + 65). You can use this program to see how the mapping works.

The output:


1 byte

q

Try it online!

This answer is exactly the same, except that it maps to lowercase alphabet characters rather than uppercase alphabet characters. This is still valid as there is no possible input character n such that chr(ord(n) % 26 + 97) == n.

x86 opcode, 6 bytes

    and     byte [ecx], 0xF1
    inc     byte [ecx]
    ret     

brainfuck, 35 27 bytes

Edit: switched to a better way of generating an odd number thanks to the brainfuck constants page

,[[[>]+<[-<]>]-[>+<---]>.,]

Try It Online

Prints out a string of semi-random Vs and Us. If the first character of the input is a V it will print out a U instead and vice versa.

How it Works

,[ Gets first inputted char 
  [[>]+<[-<]>] Converts the ASCII value to binary
  -[>+<---] Adds 85 to the last digit of that binary, which is the original value mod 2. 
            This converts a V (value 86) into a U (value 85) and vice versa
  >. Print the value
,] Get a new value and repeat. 
   Note that the binary of the previous value is still in memory, 
     so it no longer prints specific chars for odd or even values

Another version with the same bytecount:

,[[>]+<[-<]>]-[>+<---]>[.,]

Only changes the first character to a V or a U, but doesn’t handle empty input (which is still valid)

BrainFuck, 49 47 Bytes

,>++++[-<-------->]++[<]++++[->++++++++<]>-[.,]
x           0   (x-32) 2                (x-32||2)+31
^           ^(x>32) ^(x==32)

Assuming EOF as zero

C/C++, 29 bytes

void m(char*s){(*s%=26)+=65;}

Code to test :

#include <iostream>
#include <string>
#include <cassert>

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

void m(char*s){(*s%=26)+=65;}

int main() {
    std::initializer_list<std::string> test{
        "asdf",
        "1111",
        "       ",
        "~~~~~",
        "abcba",
        "1",
        " ",
        "~",
        " ~",
        "~ ",
        "  0",
        "!@#$%^&*()ABCDEFGhijklmnop1234567890",
        " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
    };

    for (auto&a : test) {
        char* t = new char[a.size() + 1];
        std::strcpy(t, a.c_str());
        m(t);
        assert(a != t);
        std::cout << a << " => " << t << '\n';
        delete[] t;
    }
}

Charcoal, 8 bytes

FSIX⁰⁼ι1

Try it online! Link is to verbose version of code. Works by comparing each character to 1, then taking the result as the exponent of zero, then converting to string. This results in an output 0 for each 1 in the input and a 1 for each other character. Edit: Changes in Charcoal now mean that I can directly cast the result of Equals saving 2 bytes: FSI⁼ι0 Try it online! Link is to verbose version of code. Edit: Actually there was a 6-byte solution all along: FS§α℅ι Try it online! Link is to verbose version of code. Port of @FlipTack's Pushy answer. (Also works with lower case of course.)

Funky, 26 22 bytes

s=>s::gsub("."a=>1&~a)

Calculates ~a which for non-digits will return NaN. Then 1& limits it to either 0 or 1, for the digit 0, this will be 1, and for 1 this will be 0. So this string is always unique.

Try it online!

Implicit, 15 14 bytes

'_._` !{+32}*-

Found about 10 interpreter bugs writing this. Try it online!

'_._` !{+32}*-
'                « read string                              »;
 _               « push last char onto stack                »;
  .              « increment                                »;
   _`            « mod by 127 (the "` " evaluates to 127)   »;
      !{...}     « if falsy (char was ~)                    »;
        +32      «  add 32 (make it a space)                »;
            *    « stick char at beginning of string        »;
             -   « pop last char off string                 »;

Golfscript, 3 bytes

Try it online!

)5%

Take the last character's ASCII value modulo 5, and replace the last character with the result. This obviously works for non-digit characters, but if the last character is a digit, it also changes ("0" mod 5 = 3, "1" mod 5 = 4, etc).

This would also work with 7 or 9 while still keeping the same length.

Also, yay! I have a Golfscript solution as good as the best solutions here!

Perl 5, 49 bytes

sub{$_="a"x length $_[0];$_++while $_ eq$_[0];$_}

Explanation:

Starting from "a"s was to avoid incrementing to point where Perl lengthens the string; with only one strings to avoid being same as, it couldn't overflow.

This is shamelessly cribbed (and simplified) from my answer to the "related" problem "The Third String".

Execute with:

perl -e '$s = ' -E 'sub{$_="a"x length $_[0];$_++while $_ eq$_[0];$_}' -E ';say $s->("z")'

Cubically, 23 bytes

(~-61/1=7&6:7>4?6@4!@5)

Converts the string into $s and -s.

T-SQL, 45 bytes

SELECT STUFF(S,1,1,CHAR(ASCII(S)%7+48))FROM t

Takes input from pre-existing table t with VARCHAR field S, per our IO standards.

Modifies the first character by taking the remainder MOD 7 of the ASCII value, then converting that back into a digit between 0 and 6. But ASCII(0)=48, which is 6 MOD 7, so the first character never maps back onto itself.

x86 Assembly, 19 bytes

Alternates the first character of the string between '@' and 'A'

_diffstr:
  00000000: 8B 54 24 04        mov         edx,dword ptr [esp+4]
  00000004: 8A 02              mov         al,byte ptr [edx]
  00000006: 3C 41              cmp         al,41h
  00000008: 75 04              jne         0000000E
  0000000A: B0 40              mov         al,40h
  0000000C: EB 02              jmp         00000010
  0000000E: B0 41              mov         al,41h
  00000010: 88 02              mov         byte ptr [edx],al
  00000012: C3                 ret

SAS, 34

substr(s,1,1)=ifc(s=:'z','a','z');

If the first character of the string s is z, change it to a, otherwise change it to z. Rubbish compared to the proper golfing languages, but at least it beats C#!

Python 2, 25 bytes

lambda s:`s<'T'`[0]+s[1:]

Try it online!

Anders Kaseorg saved a byte by extracting the first character from True or False.

Chip, 5 bytes

g*A~a

Try it online!

Maps all characters to either @ or A, so that the lowest bit always differs from the input:

0, @, ~, etc. map to A
1, a, A, etc. map to @

PHP<7.1, 31 Bytes

for(;~$c=$argn[$i++];)echo$c^1;

Try it online!

C#, 46 bytes

_=>(char)(_[0]>32?_[0]-1:_[0]+1)+_.Remove(0,1)

Changes first letter to next to previous letter on ASCII table unless it is the first letter, in which case it takes the next one.

C (gcc), 20 bytes

Saw Dennis's answer, thought of a 2 byte essential improvement.

f(char*s){*s^=*s/3;}

Try it online! (Footer by Dennis.)

Like the original, modifies the first character of the string in place, but xors it with its value divided by 3 (the smallest number that works. 2 fails on the single character 'U' which gives 127, not printable.)

Braingolf, 12 bytes

.#~e1-:1+|&@

Subtracts 1 from the last char's ordinal if it is a tilde, otherwise adds one.

Explanation:

.#~e1-:1+|&@  Implicit input of string, convert each char to ordinal and push to stack
.             Duplicate last item
 #~           Push tilde ordinal
   e          If last 2 items are equal (consumes last 2 items)
    1-        ..then subtract one
      :       else
       1+     ..add one
         |    endif
          &@  Print entire stack as chars

Brachylog, 9 bytes

{¬Ṣ|∧Ịh}ᵐ

Try it online!

Explanation

This replaces all chars by a space, except spaces which it replaces with "0".

{      }ᵐ      Map on each char of the Input
 ¬Ṣ              The Input char is not " ", and the Output char is " "
   |             Or
    ∧Ịh          The Output char is "0"

Alice, 9 bytes

#oi/
t i@

Try it online!

Explanation

The idea was taken from Martin Ender's CJam submission. The first character is taken as a code point, reduced mod 10, and moved to the end of the output. Since exactly one character was changed, permuting the characters cannot result in getting the same string back.

#   skip next command
o   (skipped)
i   push first byte onto stack
    STACK: [97]
/   reflect to SE, switch to ordinal mode (implicit reflect to SW)
i   push remaining input onto stack as string (implicit reflect to NW)
    STACK: [97, "sdf"]
o   output top of stack (implicit reflect to SW)
    STACK: [97]
t   implicitly convert code point to decimal string, and extract last character
    (implicit reflect to NE)
    STACK: ["9", "7"]
o   output this last digit (implicit reflect to SE)
i   push empty string, since there is no more input to take (implicit reflect to NE)
/   reflect to S, switch to cardinal mode
@   terminate

C (gcc), 22 bytes

f(char*s){*s=65+*s%2;}

Takes a string pointer and modies the first char in place.

Try it online!

Ruby, 20+1 = 21 bytes

Uses the -p flag.

sub(/./){$&=~/1/||1}

Try it online!

Replaces the first character in the input with a 0 if it is 1, or 1 otherwise.

Cubix, 10 bytes

..@|i?2%)O

Try it online! or Watch it run!

For each char, prints 1 if the char has an even code point, 2 otherwise; 1 has an odd code point and 2 an even, so the output will never equal the input.

Explanation

This code corresponds to the following cube net:

    . .
    @ |
i ? 2 % ) O . .
. . . . . . . .
    . .
    . .

The IP (instruction pointer) starts at the top-left corner of the far-left face, heading east. It follows this series of instructions:

i     Grab a char-code from STDIN and push it to the stack (-1 if there is no more input).
?     If the top item is negative, turn left and hit @ which ends the program.
      If it's positive (any printable ASCII char), turn right. The IP runs through a bunch
        of no-ops, then hits:
)     Increment the top item.
|     Mirror the IP's direction horizontally (turns it around).
)     Increment the top item again. The IP then wraps around again until it hits:
?     The top item is positive, so turn right.
2     Push a 2 to the stack.
%     Push the modulus of the top two items (0 for even char-code, 1 for odd).
)     Increment the result (now 1 for even char-code, 2 for odd).
O     Output as a number. The IP wraps back around to the i and the process starts again.

JavaScript (ES6), 37 33 36 29 26 18 21 19 bytes

s=>s.slice(1)+ +!+s

Try it online!

-4 bytes thanks to ETHProductions

-7 + -5 + -2 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Moves the first character to the end and sets it to 0 if it's numeric and non-zero, and 1 otherwise.

Explanation

s=>                    anonymous function with parameter s
                 +s    convert s to a number
                !      not (converts to boolean; relevant: 0->true,1->false)
               +       convert !+s back to number (true->1, false->0)
   s.slice(1)+         prefix the rest of the string
              ␣        needed to avoid the +s combining

Proof

Because the second char becomes the first, the third char becomes the second, etc. all chars would have to be identical. The last remaining char can only be a 0 or a 1, so the repeated char would have to be either 0 or 1. But any string of 0s produces a 1 at the end, and vice-versa; therefore, it is impossible to create an input that is equal to its output. -ETHProductions

See edits for former versions and explanations.

f=
s=>s.slice(1)+ +!+s

console.log(f("000"))
console.log(f("111"))
console.log(f("001"))
console.log(f("110"))
console.log(f("~"))
console.log(f("111111111111111111111111111111111111111111111111111"))
console.log(f("Hello world!"))
console.log(f("23"))
console.log(f(" "))
console.log(f("1x"))

PHP, 30 27

<?=strtr($a=$argn,$a,$a^1);

Changes every each char equal to the first char with the char that has the least significant bit flipped.

Japt, 4 bytes

®c v

Try it online!

Explanation:

®c v
®    At each char:
 c     Convert to its ASCII value
   v   Return 1 if divisible by 2, otherwise return 0

V, 7 bytes

íÁ/a
g?

Try it online! or Verify all test cases!

How does it work?

Consider all strings consisting of printable ASCII. Every string must either 1) Contain alphabetic characters, or 2) Contain no alphabetic characters.

So the way this program works is by first converting one non-alphabetic character into 'a', and then performing ROT13 on the input string.

í       " Substitute:
 Á      "   A non-alphabetic character ([^a-zA-Z])
  /     "   with
   a    "   the letter 'a'
g?      " Perform ROT13 on...
        "   (Implicit) the current line.

><>, 11 bytes

i:0(?;'0'=n

Try it online!

Explanation

Like my MATL answer, this transforms character '0' into '1' and all other characters into '0'.

i       Input one char, or push -1 if there aren't any more chars
:       Duplicate
0(      Is it less than 0?
?;      If so, end program. Else:
'0'     Push character '0'
=       Is it equal? Gives 1 or 0
n       Output as a number. Go back to the beginning

JavaScript (ES6), 24 bytes

f=
s=>s.replace(/./,s[0]^1)
<input oninput=o.textContent=f(this.value)><pre id=o>

Changes the first character of the string according to this table:

1   0
2   3
3   2
4   5
5   4
6   7
7   6
8   9
9   8

Everything else becomes 1.

Aceto, 16 12 9 bytes

=01`
,'pO

Run with -F to see immediate output (but works without).

Explanation:

We read a character, then push the character 0 on the stack and test for equality:

=0
,'

If equal, we push a 1.

  1`

We now print the top element (either a one or an implicit zero), and go back to the start:

  pO

This prints zeroes for any characters that aren't zeroes, and ones for zeroes, e.g.:

Input  |  Output
----------------
abcde  |  00000
11111  |  00000
10010  |  01101

Haskell, 19 bytes

An anonymous function which takes and returns a String. Use as (map$(!!1).show.succ) "1111".

map$(!!1).show.succ

Try it online! (Using @xnor's testing harness.)

Convex, 4 bytes

'0f=

Try it online!

Jelly, 3 bytes

~Ṿṁ

Output is a string of digits, commas and hypen-minus characters, whose first character will differ from the first character of the input string.

Try it online!

How it works

~Ṿṁ  Main link. Argument: s (string)

~    Map bitwise NOT over the characters c in s.
     This attempts to cast c to int and then apply bitwise NOT, mapping
     '0', ..., '9' to 0, ..., 9 (before ~), then -1, ..., -10 (after ~).
     For non-digits, the attempt fails, mapping c to 0.
 Ṿ   Uneval, yielding a comma-separated string of integers in [-10, ..., 0].
     The first character will be '-' if s starts with a digit and '0' if not.
  ṁ  Mold; truncate the result to the length of s.

Python 2, 21 bytes

lambda s:`s`[:len(s)]

Try it online!

Takes the string representation of the input string and truncates it to the length of the input string. For a typical string, this puts it in ' quotes and chops off the end:

abc  ->   'abc'  ->  'ab
     rep        chop

Note that the new string starts with '. Let's show that the output always differs from the input.

Finally, note that quoting the input and possibly escaping characters always increases the number of characters, so truncating the output makes it the same length as the input.

Note that it was crucial that Python adaptively switches to " in the second case. If it didn't do so, it would fail on the three-character input '\'. Or, any longer prefix of the fix show string using '. So, this method won't work for most languages.

Bash + coreutils, 13

tr \ -~ ~\ -}

Transliterates the characters to ~ (0x20 - 0x7e) with ~, then to } (0x7e, 0x20 - 0x7d).

Try it online.

05AB1E, 3 bytes

ÇÈJ

Try it online!

Ç   # Convert to ASCII values
 È  # is even? (0 is 48 and 1 is 49 therefore 0 -> 1 and 1 -> 0)
  J # Join

Jelly, 4 bytes

^1Ṿ€

Outputs a digit string. No output character will be equal to the corresponding input character.

Try it online!

How it works

^1Ṿ€  Main link. Argument: s (string)

^1    XOR each character c in with 1.
      This attempts to cast c to int, mapping '0', ..., '9' to 0, ..., 9.
      For non-digits, the attempt fails, mapping c to 0.
      After XORing with 1, we get 1, 0, 3, 2, 5, 4, 7, 6, 9, 8 for '0', ..., '9', 
      and 1 for all non-digits.
  Ṿ€  Uneval each; mapping 0, ..., 9 to '0', ..., '9'. This yields a character
      array, which is Jelly's string type.
      Note that no character is mapped to itself.

Perl 6,  48  28 bytes

{(->{[~] (' '..'~').roll(.chars)}...*ne$_).tail}

Generates a sequence of random strings, stopping when one of them doesn't match the input. Returns the last string produced

Test it

{first *ne$_,(0,1 Xx.chars)}

Generates two strings one consisting of only 0s, the other of 1s. Returns the first that is not stringwise equal to (ne) the input ($_).

Test it

Expanded

{             # bare block lambda with implicit parameter 「$_」

  first       # return the first value where the following is true

    * ne $_,  # WhateverCode lambda ( 「*」 is the parameter )

    (
      0, 1    # list of 0 and 1
      X[x]    # cross 「X」 that using the string repetition operator 「x」
      .chars  # with the number of characters in 「$_」
    )
}

MATL, 6 5 bytes

Qo!V!

Try it online!

Explanation

Q     % Implicitly input a string. Add 1 to each code point.
o     % Parity: 0 if odd, 1 if even. Note that '0' has ASCII code 48, so after
      % having added 1 it now gives 1. Similarly. '1' has ASCII code 49, so it
      % now gives 0. All other chars give 0 or 1. 
!V!   % Convert each number to the corresponding char. Implicitly display

Haskell, 20 bytes

map$head.show.(<'M')

Try it online!

Converts to a string of F and T. What matters is that the characters F and T converts to each other. This is done by checking if the character is less than M to get True or False, then taking the first character of the string representation.


Haskell, 23 bytes

q '~'=' '
q _='~'
map q

Try it online

Replaces every character with ~, except ~ becomes a space.

Whitespace, 59 bytes

Visible representation

NSSNSSSTSSSSSNSNSSNSSNSTNTSTTTTSSTNTTSNSNSTSSSNSSSNTNSSNSNN

What it does:

For every character it reads it prints a space, except when it's a space, then it prints a @.

Disassembly:

loop:
    push 32
     dup
      dup
       dup
        ichr
       get
       sub
      jn not_32
     dup
      add
not_32:
     pchr
    jmp loop

Retina, 10 6 bytes

4 bytes golfed thanks to @Neil

T`p`~p

Try it online!

This transliterates to ~, ! to , " to !, ..., ~ to }.

CJam, 5 bytes

l)iA%

Try it online!

Converts the last character to its code point and takes that modulo 10. This is clearly different for non-digit characters in the last position. But the digits start at code point 48, so taking those mod 10 will shift them left cyclically and hence the last character is always changed.

Octave, 19 18 bytes

@(s)['',(s<66)+65]

Try it online!

Explanation:

@(s)                 % Anonymous function taking a string s as input
         s<66        % A boolean vector with `1` for all characters below ASCII-66.
        (s<66)+65    % Add 65 to this, so that all elements that are 32-65 are now 66.
                     % All other elements are 65 
    ['',         ]   % Implicitly convert the list of 65 and 66 to the letters A and B

Brain-Flak, 53 bytes

Includes +1 for -c

([(((()()()()){}){}){}()]({}())){{}(<({}[()()])>)}{}

This will decrement the first character unless it is a space, in that case it will increment the first character.

Try it online!

([(((()()()()){}){}){}()]      )                     # Push: input + 1 != 33 on top of...
                         ({}())                      #    input + 1
                                {{}(<          >)}{} # If (input + 1 != 33)
                                     ({}[()()])      #   Push: (input + 1) - 2

Haskell, 30 26 bytes

f ' '='~'
f c=pred c
map f

Try it online!

Replaces each char with its predecessor and space with tilde.

05AB1E, 5 bytes

žQDÀ‡

Try it online!

Explanation

Replaces each char with the next printable ascii char, wrapping from tilde to space.

žQ     # push a string of printable acsii chars (space to tilde)
  D    # duplicate
   À   # rotate left
    ‡  # translate