Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Task/Hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions Task/Reetika Acharya/hi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 17 additions & 0 deletions Task/Reetika Acharya/q1.py
Original file line number Diff line number Diff line change
@@ -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))
28 changes: 28 additions & 0 deletions Task/Reetika Acharya/q10.py
Original file line number Diff line number Diff line change
@@ -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))

26 changes: 26 additions & 0 deletions Task/Reetika Acharya/q2.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions Task/Reetika Acharya/q3.py
Original file line number Diff line number Diff line change
@@ -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))
37 changes: 37 additions & 0 deletions Task/Reetika Acharya/q5.py
Original file line number Diff line number Diff line change
@@ -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)
35 changes: 35 additions & 0 deletions Task/Reetika Acharya/q6.py
Original file line number Diff line number Diff line change
@@ -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))
31 changes: 31 additions & 0 deletions Task/Reetika Acharya/q7.py
Original file line number Diff line number Diff line change
@@ -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))
23 changes: 23 additions & 0 deletions Task/Reetika Acharya/q8.py
Original file line number Diff line number Diff line change
@@ -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))
1 change: 0 additions & 1 deletion Task/Reetika Acharya/readme.txt

This file was deleted.

1 change: 0 additions & 1 deletion Task/Sample_Name/sampletask1.py

This file was deleted.

1 change: 0 additions & 1 deletion Task/hello.txt

This file was deleted.

1 change: 0 additions & 1 deletion Task/sample name 2/sample2.py

This file was deleted.