diff --git a/Task/Hello.txt b/Task/Hello.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Task/Hello.txt @@ -0,0 +1 @@ + diff --git a/Task/Reetika Acharya/hi.txt b/Task/Reetika Acharya/hi.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Task/Reetika Acharya/hi.txt @@ -0,0 +1 @@ + diff --git a/Task/Reetika Acharya/q1.py b/Task/Reetika Acharya/q1.py new file mode 100644 index 0000000..6fc6709 --- /dev/null +++ b/Task/Reetika Acharya/q1.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +"""Q1.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1_qefXhBTnSuDgCuwjyJm6uLQWpKgXtXy + +Q1. Given two strings s and t, return true if t is an anagram of s, and false otherwise +""" + +def is_it_anagram(a, b): + return sorted(a) == sorted(b) + +a1 = "sharp" +b1 = "harps" +print(is_it_anagram(a1, b1)) \ No newline at end of file diff --git a/Task/Reetika Acharya/q10.py b/Task/Reetika Acharya/q10.py new file mode 100644 index 0000000..8f5b771 --- /dev/null +++ b/Task/Reetika Acharya/q10.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +"""Q10.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1-817KKsWYI-BHnRzBgKoNHHsPlkrKM14 + +Problem 10: We need to transpose a 2D integer array matrix. +""" + +def transpose_matrix(matrix): + transposed = [] + for i in range(len(matrix[0])): + new_row = [] + for row in matrix: + new_row.append(row[i]) + transposed.append(new_row) + return transposed + + +matrix_input = [ + [2, 9, 0], + [7, 2, 0], + [0, 4, 1] +] +print(transpose_matrix(matrix_input)) + diff --git a/Task/Reetika Acharya/q2.py b/Task/Reetika Acharya/q2.py new file mode 100644 index 0000000..96df612 --- /dev/null +++ b/Task/Reetika Acharya/q2.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +"""Q2.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1OMuQ-7hTg1qkhu7dyIt0nX97cKzz14wx + +Problem 2: We need to count the frequency of each character in a string, considering upper and lower case letters separately, and ignoring spaces. +""" + +def frequency_of_characters(s): + freq = {} + for char in s: + if char.isalpha(): + if char in freq: + freq[char] += 1 + else: + freq[char] = 1 + + sorted_chars = sorted(freq.keys()) + for char in sorted_chars: + print("The character ", char ,", appears :", freq[char] ," number of times.") + +input_str = "The quick brown fox jumped over the lazy dog" +frequency_of_characters(input_str) \ No newline at end of file diff --git a/Task/Reetika Acharya/q3.py b/Task/Reetika Acharya/q3.py new file mode 100644 index 0000000..86a222f --- /dev/null +++ b/Task/Reetika Acharya/q3.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +"""Q3.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1sadMtX96lpZC9uzNofbnj6moykdE6JYa + +Problem 3: To increment a large integer represented as an array of digits, we can process the array from the end to handle the carry. +""" + +def increment_number(digits): + + reversed_digits = digits[::-1] + + length = len(reversed_digits) + for i in range(length): + if reversed_digits[i] < 9: + reversed_digits[i] += 1 + break + else: + reversed_digits[i] = 0 + + + digits = reversed_digits[::-1] + + return digits + + +digits_input = [1, 4, 3, 1, 9] +print(increment_number(digits_input)) \ No newline at end of file diff --git a/Task/Reetika Acharya/q5.py b/Task/Reetika Acharya/q5.py new file mode 100644 index 0000000..02f25da --- /dev/null +++ b/Task/Reetika Acharya/q5.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +"""Q5.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1CxRsflmUb0WMdPrh0IS21aJDs244tH0t + +Problem 5: Alternative way, that is taking images from a URL +""" + +# We need some additional packages +!pip install opencv-python-headless numpy requests pillow + +import cv2 +import numpy as np +import requests +from PIL import Image +from io import BytesIO +from google.colab.patches import cv2_imshow + +def detect_edges_from_url(image_url): + response = requests.get(image_url) + img = Image.open(BytesIO(response.content)).convert('RGB') + img = np.array(img) + + # Converting to grayscale + gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) + + edges = cv2.Canny(gray, 100, 200) + + cv2_imshow(cv2.cvtColor(img, cv2.COLOR_RGB2BGR)) + cv2_imshow(edges) + +# Example: +image_url = "https://www.omlet.nl/images/cache/438/512/90/Dog-Labrador_Retriever-A_healthy_adult_Labrador_sitting%2C_waiting_for_some_attention_from_it%27s_owner.webp" +detect_edges_from_url(image_url) \ No newline at end of file diff --git a/Task/Reetika Acharya/q6.py b/Task/Reetika Acharya/q6.py new file mode 100644 index 0000000..7e9ff30 --- /dev/null +++ b/Task/Reetika Acharya/q6.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +"""Q6.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1f3HVSneY4soTc8fuknWI20HUEtIpAKiO + +Problem 6: We need to find the prime numbers in an array and compute the absolute difference between the smallest and largest ones. +""" + +def is_prime(n): + if n <= 1: + return False + for i in range(2, n): + if n % i == 0: + return False + return True + +def prime_difference(N, A): + primes = [] + for i in range(N): + if is_prime(A[i]): + primes.append(A[i]) + + if len(primes) == 0: + return 1 + + smallest_prime = min(primes) + largest_prime = max(primes) + return largest_prime - smallest_prime + +A = [1, 2, 3, 4, 5, 41] # Array +N = 6 # Array Size +print(prime_difference(N, A)) \ No newline at end of file diff --git a/Task/Reetika Acharya/q7.py b/Task/Reetika Acharya/q7.py new file mode 100644 index 0000000..673e18a --- /dev/null +++ b/Task/Reetika Acharya/q7.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +"""Q7.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1FarMJ1RQ9zDo1A69GDdsPK4AgsqBNCF8 + +Problem 7: For each product, we need to find the minimum prime factor of its MRP. +""" + +def smallest_prime_factor(n): + if n <= 1: + return n + for i in range(2, n + 1): + if n % i == 0: + return i + return n + +def amount_roy_pays(N, prices): + results = [] + for price in prices: + min_prime = smallest_prime_factor(price) + roy_pays = price - min_prime + results.append(roy_pays) + return results + + +N = 2 # Array Size +prices = [5, 10] # Value of prices! +print(amount_roy_pays(N, prices)) \ No newline at end of file diff --git a/Task/Reetika Acharya/q8.py b/Task/Reetika Acharya/q8.py new file mode 100644 index 0000000..9ed4cdc --- /dev/null +++ b/Task/Reetika Acharya/q8.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +"""Q8.ipynb + +Automatically generated by Colab. + +Original file is located at + https://colab.research.google.com/drive/1q9OL93fUDpJFoQdG-z3lbX32SlDPe7Iq + +Problem 8: We need to count the frequency of each element in a list and return it as a dictionary. +""" + +def frequency_count(input_list): + frequency = {} + for element in input_list: + if element in frequency: + frequency[element] += 1 + else: + frequency[element] = 1 + return frequency + + +input_list = [1, 2, 2, 3, 3, 3] +print(frequency_count(input_list)) \ No newline at end of file diff --git a/Task/Reetika Acharya/readme.txt b/Task/Reetika Acharya/readme.txt deleted file mode 100644 index f8b8202..0000000 --- a/Task/Reetika Acharya/readme.txt +++ /dev/null @@ -1 +0,0 @@ -python taskkk diff --git a/Task/Sample_Name/sampletask1.py b/Task/Sample_Name/sampletask1.py deleted file mode 100644 index 8ed92c7..0000000 --- a/Task/Sample_Name/sampletask1.py +++ /dev/null @@ -1 +0,0 @@ -print("hello,world") diff --git a/Task/hello.txt b/Task/hello.txt deleted file mode 100644 index fa49b07..0000000 --- a/Task/hello.txt +++ /dev/null @@ -1 +0,0 @@ -new file diff --git a/Task/sample name 2/sample2.py b/Task/sample name 2/sample2.py deleted file mode 100644 index 8cde782..0000000 --- a/Task/sample name 2/sample2.py +++ /dev/null @@ -1 +0,0 @@ -print("hello world")