mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-23 08:51:31 -04:00
cleaning up and organizing old problems (builtin)
This commit is contained in:
parent
6afe96fa4d
commit
3fdbc2a605
106 changed files with 480 additions and 1472 deletions
21
src/bitwise/swap_in_place.py
Executable file
21
src/bitwise/swap_in_place.py
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
'''
|
||||
swapping values in place without extra memory
|
||||
'''
|
||||
|
||||
|
||||
def swap_bit(a, b):
|
||||
a = a^b
|
||||
b = a^b
|
||||
a = a^b
|
||||
return a, b
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = 14
|
||||
b = 73
|
||||
a2, b2 = swap_bit(a, b)
|
||||
print "a was {0}, now it is {1}. \nb was {2}, now it is {3}".format(a, a2, b, b2)
|
Loading…
Add table
Add a link
Reference in a new issue