Skip to main content
added 31 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

For integer n, you can write n+1 and n-1 as -~n and ~-n, since

  • n+1 as -~n
  • n-1 as ~-n

because the bit flip ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

or f(n)+1
or-~f(n) 

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

For integer n, you can write n+1 and n-1 as -~n and ~-n, since ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

For integer n, you can write

  • n+1 as -~n
  • n-1 as ~-n

because the bit flip ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

c/(n-1)
c/~-n

or f(n)+1
or-~f(n) 

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

Mod Removes Wiki by Doorknob
Clarified n must be int.
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

YouFor integer n, you can write n+1 and n-1 as -~n and ~-n, since ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

You can write n+1 and n-1 as -~n and ~-n, since ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

For integer n, you can write n+1 and n-1 as -~n and ~-n, since ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.

Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

You can write n+1 and n-1 as -~n and ~-n, since ~x equals -1-x. This uses the same number of characters, but can indirectly cut spaces or parens for operator precedence.

Compare:

while n-1:  #Same as while n!=1 
while~-n:

(n+1)*2
-~n*2

c/(n-1)
c/~-n

(n-1)/10+(n-1)%10
~-n/10+~-n%10

The operators ~ and unary - are higher precedence than *, /, %, unlike binary +.