From 2a422c2ad50a5f4521345d8c6fb49a174fc55c9c Mon Sep 17 00:00:00 2001 From: Lazo Date: Sun, 17 Oct 2021 14:44:16 +0300 Subject: [PATCH 1/3] Adding homework folder and uploading homework 1 --- .../19_Lachezar_Velinov/01_checkCircles.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 homeworks/19_Lachezar_Velinov/01_checkCircles.py diff --git a/homeworks/19_Lachezar_Velinov/01_checkCircles.py b/homeworks/19_Lachezar_Velinov/01_checkCircles.py new file mode 100644 index 0000000..3f25354 --- /dev/null +++ b/homeworks/19_Lachezar_Velinov/01_checkCircles.py @@ -0,0 +1,41 @@ +import math + +class Circle: + def __init__(self, x, y, rad): # a constructor for the circle class + self.x = x + self.y = y + self.rad = rad + + +# the abs function is equal to a module in mathematics. +def find_centre_distance(Circle1, Circle2): + x_axis = abs(Circle1.x - Circle2.x) + y_axis = abs(Circle1.y - Circle2.y) + + if(x_axis == 0 and y_axis == 0): + distance = 0 + else: + distance = math.sqrt((x_axis**2) + (y_axis**2)) # using the Pythagorean theorem to find the distance between the 2 centres + + + if(distance > (Circle1.rad + Circle2.rad)): + print("No common") + elif(distance < (Circle1.rad + Circle2.rad)): + if(distance == 0 and Circle1.rad == Circle2.rad): + print("Circles are matching") + elif((distance + Circle1.rad) < Circle2.rad): + print("Circle one is inside circle two") + elif((distance + Circle2.rad) < Circle1.rad): + print("Circle two is inside circle one") + else: + print("The circles are intersecting") + + else: + print("The circles are touching") + + + +Circle1 = Circle(2, 4, 3) +Circle2 = Circle(4, 4, 5) + +find_centre_distance(Circle1, Circle2) \ No newline at end of file From 495116564353d9160ccfe7e937429ccfda527941 Mon Sep 17 00:00:00 2001 From: Lachezar-Velinov Date: Wed, 12 Jan 2022 22:16:33 +0200 Subject: [PATCH 2/3] Upload homework 2, fix folder name --- .../01_checkCircles.py | 0 homeworks/18_Lachezar_Velinov/02_task1.py | 51 +++++++++++++++++++ homeworks/18_Lachezar_Velinov/02_task2.py | 11 ++++ homeworks/18_Lachezar_Velinov/02_task3.py | 16 ++++++ 4 files changed, 78 insertions(+) rename homeworks/{19_Lachezar_Velinov => 18_Lachezar_Velinov}/01_checkCircles.py (100%) create mode 100644 homeworks/18_Lachezar_Velinov/02_task1.py create mode 100644 homeworks/18_Lachezar_Velinov/02_task2.py create mode 100644 homeworks/18_Lachezar_Velinov/02_task3.py diff --git a/homeworks/19_Lachezar_Velinov/01_checkCircles.py b/homeworks/18_Lachezar_Velinov/01_checkCircles.py similarity index 100% rename from homeworks/19_Lachezar_Velinov/01_checkCircles.py rename to homeworks/18_Lachezar_Velinov/01_checkCircles.py diff --git a/homeworks/18_Lachezar_Velinov/02_task1.py b/homeworks/18_Lachezar_Velinov/02_task1.py new file mode 100644 index 0000000..de530ee --- /dev/null +++ b/homeworks/18_Lachezar_Velinov/02_task1.py @@ -0,0 +1,51 @@ + + +def getSectorValues(matrix, rowpos, columnpos, sectorList): #finds all the values of a sector and returns them + sectorList.append(matrix[rowpos][columnpos]) + matrix[rowpos][columnpos] = 0 #turns an appended square into a black square + for i in range(-1, 2): + for j in range(-1, 2): + if rowpos + i >= 0 and columnpos + j >= 0 and rowpos + i < len(matrix) and columnpos + j < len(matrix[i]): #check if location is in range of the matrix + if matrix[rowpos+i][columnpos+j] != 0: #check if square is non black + getSectorValues(matrix, rowpos+i, columnpos+j, sectorList) #reccursive calling + return + + +def findSector(matrix): #looks for a sector and returns it's average value + returnValueList = [] #holds average value of every sector + sectorList = [] #holds all the values of a single sector + for rowpos, row in enumerate(matrix): + for columnpos, column in enumerate(row): #go throught the matrix to find a non black square + if matrix[rowpos][columnpos] > 0: + getSectorValues(matrix, rowpos, columnpos, sectorList) + average = 0 #average value of a sector + for amount in sectorList: + average+=amount + average /= len(sectorList) + del sectorList[:] #reset the sector list + returnValueList.append(average) #add average sector value to rest list + + return returnValueList + + +def avg_brightnes(matrix): + outputList = [] + outPutList = findSector(matrixCopy) + outPutList.sort(reverse=True) #sort list in descending order + for i in outPutList: #prints final values + print (i) + + + + +matrix = ( #test matrix + (170, 0, 0, 255, 221, 0), + ( 68, 0, 17, 0, 0, 68), + (221, 0, 238, 136, 0, 255), + ( 0, 0, 85, 0, 136, 238), + (238, 17, 0, 68, 0, 255), + ( 85, 170, 0, 221, 17, 0) +) + +matrixCopy = [list(matrix_inner) for matrix_inner in matrix] #since we cannot use the original matrix, we make a copy +avg_brightnes(matrixCopy) diff --git a/homeworks/18_Lachezar_Velinov/02_task2.py b/homeworks/18_Lachezar_Velinov/02_task2.py new file mode 100644 index 0000000..a0e79b2 --- /dev/null +++ b/homeworks/18_Lachezar_Velinov/02_task2.py @@ -0,0 +1,11 @@ +from functools import lru_cache + + +@lru_cache(maxsize=10) #allows us to use 10 most recent values by caching them +def num_ways(n): + if n <= 1: + return n + return num_ways(n-1) + num_ways(n-2) + + +print(num_ways(23)) \ No newline at end of file diff --git a/homeworks/18_Lachezar_Velinov/02_task3.py b/homeworks/18_Lachezar_Velinov/02_task3.py new file mode 100644 index 0000000..86f1f08 --- /dev/null +++ b/homeworks/18_Lachezar_Velinov/02_task3.py @@ -0,0 +1,16 @@ +def replace(List, Find, Replace): + listCopy = list(List) + + for i, value in enumerate(listCopy): #go through list + if value == Find: + listCopy[i] = Replace #looks for value and replaces it + + elif type(value) in [list, tuple]: + listCopy[i] = replace(listCopy[i], Find, Replace) #if container is found, goes inside it + + return listCopy + + +exampleList = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'b')] +res = replace(exampleList, 'a', 'c') +print(res) \ No newline at end of file From c1fef00c402bdc36d03eeae783d617957bef9219 Mon Sep 17 00:00:00 2001 From: Lachezar-Velinov Date: Wed, 12 Jan 2022 22:23:39 +0200 Subject: [PATCH 3/3] add endline at end of files --- homeworks/18_Lachezar_Velinov/02_task2.py | 2 +- homeworks/18_Lachezar_Velinov/02_task3.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeworks/18_Lachezar_Velinov/02_task2.py b/homeworks/18_Lachezar_Velinov/02_task2.py index a0e79b2..bc4afe0 100644 --- a/homeworks/18_Lachezar_Velinov/02_task2.py +++ b/homeworks/18_Lachezar_Velinov/02_task2.py @@ -8,4 +8,4 @@ def num_ways(n): return num_ways(n-1) + num_ways(n-2) -print(num_ways(23)) \ No newline at end of file +print(num_ways(23)) diff --git a/homeworks/18_Lachezar_Velinov/02_task3.py b/homeworks/18_Lachezar_Velinov/02_task3.py index 86f1f08..5dc174e 100644 --- a/homeworks/18_Lachezar_Velinov/02_task3.py +++ b/homeworks/18_Lachezar_Velinov/02_task3.py @@ -13,4 +13,4 @@ def replace(List, Find, Replace): exampleList = [ 'a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'b')] res = replace(exampleList, 'a', 'c') -print(res) \ No newline at end of file +print(res)