mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
23 lines
298 B
Python
Executable File
23 lines
298 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
__author__ = "bt3"
|
|
|
|
'''
|
|
swapping values in place without extra memory
|
|
'''
|
|
|
|
|
|
def swap_bit(a, b):
|
|
'''
|
|
>>> swap_bit(14, 73)
|
|
(73, 14)
|
|
'''
|
|
a = a^b
|
|
b = a^b
|
|
a = a^b
|
|
return a, b
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import doctest
|
|
doctest.testmod() |