From 77f4c37eb3400dbf143e85e7b74b92bef7478fac Mon Sep 17 00:00:00 2001 From: suvanbalu Date: Mon, 13 Sep 2021 18:04:12 +0530 Subject: [PATCH 1/2] bit manipulation and linear_search change --- algorithms/bit manipulation/xor_swap.py | 14 ++++++++++++++ algorithms/searches/linear_search.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 algorithms/bit manipulation/xor_swap.py diff --git a/algorithms/bit manipulation/xor_swap.py b/algorithms/bit manipulation/xor_swap.py new file mode 100644 index 0000000..05de060 --- /dev/null +++ b/algorithms/bit manipulation/xor_swap.py @@ -0,0 +1,14 @@ +from typing import List + + +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)) From e00980a3f0667c8c8630325bb9dfcd934641688f Mon Sep 17 00:00:00 2001 From: suvanbalu Date: Tue, 14 Sep 2021 09:04:47 +0530 Subject: [PATCH 2/2] Created bitwise algorithms --- algorithms/bit manipulation/twice_unique.py | 11 +++++++++++ algorithms/bit manipulation/xor_swap.py | 3 --- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 algorithms/bit manipulation/twice_unique.py 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 index 05de060..1c6063a 100644 --- a/algorithms/bit manipulation/xor_swap.py +++ b/algorithms/bit manipulation/xor_swap.py @@ -1,6 +1,3 @@ -from typing import List - - def swap(a:int,b:int) -> list : a=a^b b=b^a pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy