Skip to main content
Added proof from @ETHProductions
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117

#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            +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"))

#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

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"))

#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"))

Saved 2 bytes
Source Link

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

s=>+!+s[0]+ss=>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

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

###Explanation

s=>                    anonymous function with parameter s
     +s[0] +s            convert the first character inconvert 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)+       +s.slice(1)  concatenateprefix the rest of the string
              ␣        needed to avoid the +s combining

See edits for former versions and explanations.

f=
s=>+!+s[0]+ss=>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"))

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

s=>+!+s[0]+s.slice(1)

-4 bytes thanks to ETHProductions

-7 + -5 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Sets the first character to 0 if the first character is numeric and non-zero, and sets the first character to 1 otherwise.

###Explanation

s=>                    anonymous function with parameter s
     +s[0]             convert the first character in 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)  concatenate the rest of the string

See edits for former versions and explanations.

f=
s=>+!+s[0]+s.slice(1)

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"))

#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

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"))

added 57 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117

#JavaScript (ES6), 37 33 36 29 26 1818 21 bytes

s=>+!+s+s+s[0]+s.slice(1)

-4 bytes thanks to ETHProductions

-7 + -5 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Sets the first character to 0 if the first character is numeric and non-zero, and sets the first character to 1 otherwise.

###Explanation

s=>                    anonymous function with parameter s
     +s+s[0]             convert the first character in 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)  concatenate the rest of the string

See edits for former versions and explanations.

f=
s=>+!+s+s+s[0]+s.slice(1)

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"))

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

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

-4 bytes thanks to ETHProductions

-7 + -5 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Sets the first character to 0 if the first character is numeric and non-zero, and sets the first character to 1 otherwise.

###Explanation

s=>                 anonymous function with parameter s
     +s             convert the first character in 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)  concatenate the rest of the string

See edits for former versions and explanations.

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

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(" "))

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

s=>+!+s[0]+s.slice(1)

-4 bytes thanks to ETHProductions

-7 + -5 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Sets the first character to 0 if the first character is numeric and non-zero, and sets the first character to 1 otherwise.

###Explanation

s=>                    anonymous function with parameter s
     +s[0]             convert the first character in 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)  concatenate the rest of the string

See edits for former versions and explanations.

f=
s=>+!+s[0]+s.slice(1)

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"))

deleted 48 characters in body; Post Made Community Wiki
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
added 18 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
deleted 10 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
deleted 10 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
added 57 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
added 57 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
added 116 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
added 249 characters in body
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading
Source Link
Stephen
  • 14k
  • 3
  • 52
  • 117
Loading