Ranter
Join devRant
Do all the things like
++ or  rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Comments


kamen29518dNow that I checked, destructuring is also available in vanilla ES6 (though not in IE).

Parzi16288da = str(a)+str(b)
b = int(a[:len(b)1])
a = int(a[len(b)1:])
Technically this would work in Python but the original Python method would be easier. 
Parzi16288d@LinusTorvald we're talking generally, not edge cases. However, if you have 2 variables with INT_MAX, why swap them?

Fabian8188dI've once written a Fibonacchi program in Java using only two variables. Without recursion!
https://codegolf.stackexchange.com/...
With recursion, it would be easy with one variable, but also horribly slow. My version has basically normal runtime. 
Rocket3G2188d@LinusTorvald in most programming languages, INT_MAX+1 = INT_MIN, because the way overflowing works.
Given the case of a=6 and b=7 and INT_MIN=10 and INT_MAX = 10:
a=a+b
b=ab
a=ab
a = 6+7 = 13 = 7
b= 7  7 = 14 = 6
a=7  6 = 13 = 7
Therefore a and b are indeed swapped. The only case where it doesn't work if either a or b are larger than INT_MAX or less than INT_MIN 
PaperBag6798d@LinusTorvald Not accurate. If the sum overflows, then it will just overflow back when you subtract from it.
Let's say the range is 09 and a = 5, b = 7:
a = 5 + 7 = 2
b = 2  7 = 5
a = 2  5 = 7 
tokumei22688d@Rocket3G @PaperBag That's only true for Clike languages though, and only in architectures where signed numbers are either twos complement or biased. Technically speaking, implicitly overflowing signed integers is undefined behavior because of the varying implementations in the general case.

Parzi16288d@LinusTorvald the way you put it made it look like you were using an edge case where both a AND b were INT_MAX.


tokumei22684d@Gregozor2121
a = 0xf00d
b = 0xf00d
a ^= b // 0xf00d ^ 0xf00d == 0
b ^= a // 0xf00d ^ 0 == 0xf00d
a ^= b // 0 ^ 0xf00d == 0xf00d 
@tokumei
Well Cnotesforprofessionals have said otherwise that is why i had doubts
Deal with it bitych! ðŸ˜‚
joke/meme
python
programmer