@BobRichardson-s8y

Smart people struggle for simplicity while foolish people admire complexity.

@Prakhar-Diaries

A = a+b
B = a- b

A = a - b

@RickoDeSea

The first 1 is cool but the second is how good software is written 😎

@jeetanime

a,b=b,a
From python

@truetruetruly2163

XOR swap is objectively an unoptimal way of swapping two variables. Depending on the language, most compilers will just optimize it for you if you write it the second way.

@hgcno2-y1o

using System;
public class Program {
    int a = 2, b = 3;
    private static void Main() {
         a = a+b;
         b = a-b;
         a = a-b
     }
}

@user-br8vf6jy3w

In python a, b = b, a

@speedingAtI94

It's just a space time trade off. The first option doesn't use temp variable but needs 3 XOR instead of 2 loads.

@phuongpham8076

Please, dont do a = a + b.... like other comment in PROD, if the number is too bigg it will make i64 or some like that out of range. Use temp var

@mikey7165

BE CAREFUL WITH XOR! if the numbers u are swapping is the same it will return 0 on every bit. So it will make both 0 instead of swapping them meaning u need an if statement if u want to use it.

@Rvwondervlog

Let A =10
Let B= 20 
a = a + b // a become 30 
b = a - b // b becom 10 
a = a - b a becom 20 

Consol.log(a,b)

@ortezan4186

Doesn't work on floating point numbers and  only useful for learning bitwise operators. Has no real life application.

@abdulnafay72

[a,b] = [b,a]

@elifelif9377

XOR ❌️
Temp ❌️
XCHG (Exchange) βœ…οΈβœ…οΈ

@SolevoyLihodey

a = a + b - (b = a);

@stalin_botinok9862

(a, b) = (b, a)

@ChandrahaS-YT

b=a^b(a=b)

@mikkel6437

Second one will get corrected to the first one and give the exact same output in most compilers.

@mihir.vs09

a,b = b,a πŸ—ΏπŸ—Ώ(python)

@dxcfvg456hkjtyujk

Yes was asked in Morgan Stanley (MSCI)