Post History
Replace n+1 with -~n and n-1 with ~-n For integers, n+1 and ~-n have the same value, as have n-1 and -~n. While the expressions themselves have the same lengths, the replacements often allow to s...
Answer
#2: Post edited
- # Replace `n+1` with `-~n` and `n-1` with `~-n`
- For integers, `n+1` and `~-n` have the same value, as have `n-1` and `-~n`.
While the expressions themselves have the same lengths, the replacements often allow to save space by allowing either to remove whitespace or omit parentheses due to different precedence.- For example,
- ```
- a=12*(n+1)
- ```
- can be replaced by
- ```
- a=12*-~n
- ```
- # Replace `n+1` with `-~n` and `n-1` with `~-n`
- For integers, `n+1` and `~-n` have the same value, as have `n-1` and `-~n`.
- While the expressions themselves have the same lengths, the replacements often allow to save space by allowing either to remove whitespace or to omit parentheses due to different precedence.
- For example,
- ```
- a=12*(n+1)
- ```
- can be replaced by
- ```
- a=12*-~n
- ```
#1: Initial revision
# Replace `n+1` with `-~n` and `n-1` with `~-n` For integers, `n+1` and `~-n` have the same value, as have `n-1` and `-~n`. While the expressions themselves have the same lengths, the replacements often allow to save space by allowing either to remove whitespace or omit parentheses due to different precedence. For example, ``` a=12*(n+1) ``` can be replaced by ``` a=12*-~n ```