diff --git a/algorithms/bit manipulation/twice_unique.py b/algorithms/bit manipulation/twice_unique.py new file mode 100644 index 0000000..3439c0a --- /dev/null +++ b/algorithms/bit manipulation/twice_unique.py @@ -0,0 +1,11 @@ +def twice_unique(arr:list) : + unique = 0 + for i in arr: + unique ^= i + return unique +if __name__=="__main__": + array = list(map(int,input().split())) + #sample input + # 1 2 2 3 4 4 3 + element = twice_unique(array) + print(f"Unique element in the array {array} is {element}") diff --git a/algorithms/bit manipulation/xor_swap.py b/algorithms/bit manipulation/xor_swap.py new file mode 100644 index 0000000..1c6063a --- /dev/null +++ b/algorithms/bit manipulation/xor_swap.py @@ -0,0 +1,11 @@ +def swap(a:int,b:int) -> list : + a=a^b + b=b^a + a=a^b + return [a,b] + +if __name__=="__main__": + a=int(input("Enter Number 1 : ")) + b = int(input("Enter Number 2 : ")) + AfterSwap= swap(a,b) + print(f"After Swap : {AfterSwap[0],AfterSwap[1]}") diff --git a/algorithms/searches/linear_search.py b/algorithms/searches/linear_search.py index 76a17a4..1d44b64 100644 --- a/algorithms/searches/linear_search.py +++ b/algorithms/searches/linear_search.py @@ -10,4 +10,4 @@ def linear_search(arr, item): # Tests -print(search([1,2,3,4,5], 3)) +print(linear_search([1,2,3,4,5], 3))