From 30c949ab86f9d67a369306d6572c42d0b5e5fc6b Mon Sep 17 00:00:00 2001 From: yavor2 <85577690+yavor2@users.noreply.github.com> Date: Sat, 16 Oct 2021 16:34:46 +0300 Subject: [PATCH 1/3] Homework 1. Check two circles. --- .../26_Yavor_Pachedjiev/01_check_circles.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 homeworks/26_Yavor_Pachedjiev/01_check_circles.py diff --git a/homeworks/26_Yavor_Pachedjiev/01_check_circles.py b/homeworks/26_Yavor_Pachedjiev/01_check_circles.py new file mode 100644 index 0000000..b0dbf5b --- /dev/null +++ b/homeworks/26_Yavor_Pachedjiev/01_check_circles.py @@ -0,0 +1,36 @@ +from math import sqrt + +def check_Circles(c1_center, c1_rad, c2_center, c2_rad): + if(c1_center == c2_center and c1_rad == c2_rad): + return "Matching" + c1_x, c1_y = c1_center + c2_x, c2_y = c2_center + + distance = sqrt((c2_y - c1_y)**2 + (c2_x - c1_x)**2) + rad_sum = c1_rad + c2_rad + if(rad_sum < distance): + return "not intesecting" + if(rad_sum == distance): + return "touching" + if(rad_sum > distance): + if(distance + c1_rad <= c2_rad): + if(c1_rad + distance == c2_rad): + return "Circle B contains circle A and they are touching" + else: + return "Circle B contains circle A" + elif(distance + c2_rad <= c1_rad): + if(c1_rad == c2_rad + distance): + return "Circle A contains circle B and they are touching" + else: + return "Circle A contains circle B" + else: + return "intersecting" + + +a_c = (-7,5) +b_c = (4,5) + +a_r = 3 +b_r = 14 + +print(check_Circles(a_c, a_r, b_c, b_r)) From c229d330efc493bfdb0b3904366517a3d74f3833 Mon Sep 17 00:00:00 2001 From: yavor2 <85577690+yavor2@users.noreply.github.com> Date: Sat, 6 Nov 2021 15:00:12 +0200 Subject: [PATCH 2/3] Add candy from October 18th with fixed class number --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c42903..1368e66 100644 --- a/README.md +++ b/README.md @@ -60,5 +60,5 @@ $ marp 01.md && open 01.html |22| Пламен Цоков | [PlamenTs18](https://github.com/PlamenTs18) | | | |23| Симеон Христов | [ItzNinjaCat](https://github.com/ItzNinjaCat) | | | |24| Станислав Иванов | [Stanislav04](https://github.com/Stanislav04) | | | -|25| Явор Пачеджиев| [yavor2](https://github.com/yavor2) | | | +|25| Явор Пачеджиев| [yavor2](https://github.com/yavor2) | 🍬 | | |26| Ясен Ефремов | [YassenEfremov](https://github.com/YassenEfremov) | 🍬🍬🍬 | | From f257694d1a4093d461ee78c8a2d17671911145b0 Mon Sep 17 00:00:00 2001 From: yavor2 <85577690+yavor2@users.noreply.github.com> Date: Thu, 13 Jan 2022 09:18:11 +0200 Subject: [PATCH 3/3] Upload homework 2 --- .../second_homework/zad1.py | 67 +++++++++++++++++++ .../second_homework/zad2.py | 9 +++ .../second_homework/zad3.py | 29 ++++++++ 3 files changed, 105 insertions(+) create mode 100644 homeworks/26_Yavor_Pachedjiev/second_homework/zad1.py create mode 100644 homeworks/26_Yavor_Pachedjiev/second_homework/zad2.py create mode 100644 homeworks/26_Yavor_Pachedjiev/second_homework/zad3.py diff --git a/homeworks/26_Yavor_Pachedjiev/second_homework/zad1.py b/homeworks/26_Yavor_Pachedjiev/second_homework/zad1.py new file mode 100644 index 0000000..9e60ef1 --- /dev/null +++ b/homeworks/26_Yavor_Pachedjiev/second_homework/zad1.py @@ -0,0 +1,67 @@ + +def get_neighbours(index, matrix): + offsets = [[-1,-1], [-1,0], [-1,1], [0,1], [1,1], [1,0], [1,-1], [0,-1]] + + neighbours = [] + neighbour = [] + for offset in offsets: + neighbour = [x + y for x, y in zip(offset, index)] + if (neighbour[0] >= 0 and neighbour[0] < len(matrix)) and (neighbour[1] >= 0 and neighbour[1] < len(matrix[neighbour[0]])): + if matrix[neighbour[0]][neighbour[1]] != 0: + neighbours.append(neighbour) + return neighbours #returns index + + +def calculate_sum(matrix, index, has_accessed=[]): + brightness = matrix[index[0]][index[1]] + has_accessed.append(index) + + neighbours = get_neighbours(index, matrix) + neighbours = [neighbour for neighbour in neighbours if neighbour not in has_accessed] + + # print(index, ':', neighbours) + + if(len(neighbours) == 0): + return brightness + + for neighbour in neighbours: + if neighbour not in has_accessed: + brightness += calculate_sum(matrix, neighbour, has_accessed) + return brightness + + + + + +def avg_brightness(matrix): + has_accessed = [] + sum = 0 + old_len = 0 + cells = 0 + + for i, row in enumerate(matrix): + for j, elem in enumerate(row): + if matrix[i][j] == 0 or [i,j] in has_accessed: + continue + # neighbours = get_neighbours([i,j], matrix) + sum = calculate_sum(matrix, [i,j], has_accessed) + cells = len(has_accessed) - old_len + + print("Sum:", sum) + print("Cells:", cells) + print("Average brightness:", sum/cells, "\n") + old_len += cells + + + +matrix = [ + [85, 0, 0, 108], + [0, 0, 127, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 7, 0], + [0, 0, 0, 0], + [0, 9, 0, 0], + [0, 0, 0, 0] + ] +avg_brightness(matrix) \ No newline at end of file diff --git a/homeworks/26_Yavor_Pachedjiev/second_homework/zad2.py b/homeworks/26_Yavor_Pachedjiev/second_homework/zad2.py new file mode 100644 index 0000000..b0f12ad --- /dev/null +++ b/homeworks/26_Yavor_Pachedjiev/second_homework/zad2.py @@ -0,0 +1,9 @@ +import sys +# add mzlat +def num_ways(steps): + if steps <= 1: + return 1 + return num_ways(steps-1) + num_ways(steps-2) + +# sys.setrecursionlimit(1500) +print(num_ways(4)) diff --git a/homeworks/26_Yavor_Pachedjiev/second_homework/zad3.py b/homeworks/26_Yavor_Pachedjiev/second_homework/zad3.py new file mode 100644 index 0000000..b73475d --- /dev/null +++ b/homeworks/26_Yavor_Pachedjiev/second_homework/zad3.py @@ -0,0 +1,29 @@ +def replaceFunc(the_list, find, replace): + if not isinstance(the_list, tuple) and not isinstance(the_list, list): + if isinstance(the_list, str): + if the_list == 'a': + return 'c' + else: + return the_list + + return the_list + + new_list = [] + + for i in range(len(the_list)): + item = the_list[i] + if isinstance(item, tuple): + new_list.append(tuple(replaceFunc(item, find, replace))) + else: + new_list.append(replaceFunc(item, find, replace)) + + return new_list + + +# tl = [2, 3, [2, 3, [7, 8], 2], (9,( 0,3, (4,5))), 1] +tl = ['a', 1, [ ['a', 'b'], 1], ([1, 3, 'a'], 'b')] + +nl = replaceFunc(tl, 'a', 'c') + +print(tl) +print(nl) \ No newline at end of file