
보통 개발자의 자리이동은 세개의 의자가 있어야지만 가능하다.
빈의자 = 개발자1 개발자1 = 개발자2 개발자1 = 빈의자
```bash
그런데 XOR를 이용하면 두개의 의자 만으로도 이동이 가능하다.
```bash
개발자1 ^= 개발자2 개발자2 ^= 개발자1 개발자1 ^= 개발자2
```bash

GPT의 답변이다. 나는 이런 방법이 있을거라 생각도 못했었다.
그러던중 현대의 컴파일러에선 XOR가 메모리를 사용하지 않지만 병렬처리에서의 문제로 성능이 떨어진다는 이야기를 들었다.

항상 자세한 설명과 함께 도움주시는 pr0gr4m 님.
느려지는게 맞다고 하셔서 궁금해서 돌려봤다.
```bash
import timeit
# temp 사용 def swap_temp():
a = 5
b = 10
temp = a
a = b
b = temp
return a, b
# XOR 사용 def swap_xor():
a = 5
b = 10
a ^= b
b ^= a
a ^= b
return a, b
# 성능 테스트 temp_time = timeit.timeit("swap_temp()", setup="from __main__ import swap_temp", number=1000000) xor_time = timeit.timeit("swap_xor()", setup="from __main__ import swap_xor", number=1000000)
print(f"Using temp: {temp_time} seconds") print(f"Using XOR: {xor_time} seconds")
```bash
코드를 여러번 실행해 봤고 결론을 얻었다.
```bash
linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04701741598546505 seconds Using XOR: 0.06559245800599456 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04990166565403342 seconds Using XOR: 0.06569029204547405 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04502225015312433 seconds Using XOR: 0.0672295419499278 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.045115040615200996 seconds Using XOR: 0.06622312497347593 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.044884291011840105 seconds Using XOR: 0.06595424981787801 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04486312484368682 seconds Using XOR: 0.06613395782187581 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04502458404749632 seconds Using XOR: 0.06623658305034041 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.044890208169817924 seconds Using XOR: 0.0665586250834167 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.045562250073999166 seconds Using XOR: 0.06695195799693465 seconds linus@Linusui-MacBookPro python % /opt/homebrew/bin/python3 /Users/linus/Desktop/python/test.py Using temp: 0.04477795818820596 seconds Using XOR: 0.06620474997907877 seconds
```bash
아 궁금함이 풀렸다.
결론
## **개발자 두명은 의자 두개로 자리 이동이 가능하지만 느리다.**
또,

Pr0gr4m의 추가 답변이 있었다.
알수록 어려운 컴파일러의 세계다.