From c40d769fe67c68a70cfa4d1eb074b53531aa2ecc Mon Sep 17 00:00:00 2001 From: kotka <47333381+ItzNinjaCat@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:42:46 +0200 Subject: [PATCH 1/4] Create 24_Simeon_Hristov --- homeworks/24_Simeon_Hristov | 1 + 1 file changed, 1 insertion(+) create mode 100644 homeworks/24_Simeon_Hristov diff --git a/homeworks/24_Simeon_Hristov b/homeworks/24_Simeon_Hristov new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/homeworks/24_Simeon_Hristov @@ -0,0 +1 @@ + From 7e2a26dcab9fcb8416fb972b5aa38ecd8ba80e57 Mon Sep 17 00:00:00 2001 From: kotka <47333381+ItzNinjaCat@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:43:03 +0200 Subject: [PATCH 2/4] Delete 24_Simeon_Hristov --- homeworks/24_Simeon_Hristov | 1 - 1 file changed, 1 deletion(-) delete mode 100644 homeworks/24_Simeon_Hristov diff --git a/homeworks/24_Simeon_Hristov b/homeworks/24_Simeon_Hristov deleted file mode 100644 index 8b13789..0000000 --- a/homeworks/24_Simeon_Hristov +++ /dev/null @@ -1 +0,0 @@ - From 96caca932da78893f30f42b82492b588581bc428 Mon Sep 17 00:00:00 2001 From: kotka <47333381+ItzNinjaCat@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:44:21 +0200 Subject: [PATCH 3/4] Create 01_check_circles.py --- .../24_Simeon_Hristov/01_check_circles.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 homeworks/24_Simeon_Hristov/01_check_circles.py diff --git a/homeworks/24_Simeon_Hristov/01_check_circles.py b/homeworks/24_Simeon_Hristov/01_check_circles.py new file mode 100644 index 0000000..02c0715 --- /dev/null +++ b/homeworks/24_Simeon_Hristov/01_check_circles.py @@ -0,0 +1,22 @@ +from math import sqrt + +def checkCircle(c1_center, c1_radius, c2_center, c2_radius): + if c1_center == c2_center and c1_radius == c2_radius: + return "The circles are matching" + c1_x, c1_y = c1_center + c2_x, c2_y = c2_center + + d = sqrt((c1_x - c2_x)**2+(c1_y - c2_y)**2) + sum_of_radii = c1_radius + c2_radius + + if d == sum_of_radii: + return "The circles touch" + elif d < sum_of_radii: + if d + c2_radius <= c1_radius: + return "Circle one contains circle two" + elif d + c1_radius <= c2_radius: + return "Circle two contains circle one" + else: + return "The circles intersect" + elif d > sum_of_radii: + return "The circles do not intersect" From f8a565f2f2f070f596e81de00c51506385387b45 Mon Sep 17 00:00:00 2001 From: kotka <47333381+ItzNinjaCat@users.noreply.github.com> Date: Wed, 12 Jan 2022 23:13:38 +0200 Subject: [PATCH 4/4] Add files via upload --- .../24_Simeon_Hristov/02_avg_brigthness.py | 65 +++++++++++++++++++ homeworks/24_Simeon_Hristov/02_num_ways.py | 8 +++ homeworks/24_Simeon_Hristov/02_replace.py | 16 +++++ 3 files changed, 89 insertions(+) create mode 100644 homeworks/24_Simeon_Hristov/02_avg_brigthness.py create mode 100644 homeworks/24_Simeon_Hristov/02_num_ways.py create mode 100644 homeworks/24_Simeon_Hristov/02_replace.py diff --git a/homeworks/24_Simeon_Hristov/02_avg_brigthness.py b/homeworks/24_Simeon_Hristov/02_avg_brigthness.py new file mode 100644 index 0000000..20ab0d9 --- /dev/null +++ b/homeworks/24_Simeon_Hristov/02_avg_brigthness.py @@ -0,0 +1,65 @@ +from copy import deepcopy +from random import randint + +def check_sides(matrix, x, y, shape_coords_list = None): + matrix_cpy = matrix + if shape_coords_list is None: + shape_coords_list = [] + shape_coords_list.append((x, y)) + matrix_cpy[x][y] = 0 + if x - 1 >= 0 and matrix_cpy[x - 1][y] != 0: + check_sides(matrix_cpy, x - 1, y, shape_coords_list) + + if y - 1 >= 0 and matrix_cpy[x][y - 1] != 0: + check_sides(matrix_cpy, x, y - 1, shape_coords_list) + + if y + 1 < len(matrix[0]) and matrix_cpy[x][y + 1] != 0: + check_sides(matrix_cpy, x, y + 1, shape_coords_list) + + if x + 1 < len(matrix) and matrix_cpy[x + 1][y] != 0: + check_sides(matrix_cpy, x + 1, y, shape_coords_list) + + if x - 1 >= 0 and y - 1 >= 0 and matrix_cpy[x - 1][y - 1] != 0: + check_sides(matrix_cpy, x - 1, y - 1, shape_coords_list) + + if x - 1 >= 0 and y + 1 < len(matrix[0]) and matrix_cpy[x - 1][y + 1] != 0: + check_sides(matrix_cpy, x - 1, y + 1, shape_coords_list) + + if x + 1 < len(matrix) and y - 1 >= 0 and matrix_cpy[x + 1][y - 1] != 0: + check_sides(matrix_cpy, x + 1, y - 1, shape_coords_list) + + if x + 1 < len(matrix) and y + 1 < len(matrix[0]) and matrix_cpy[x + 1][y + 1] != 0: + check_sides(matrix_cpy, x + 1, y + 1, shape_coords_list) + + return shape_coords_list + +def brigthness(list, matrix): + sum = 0 + for i in list: + x = i[0] + y = i[1] + sum += matrix[x][y] + return (sum / len(list)) + +def avg_brigthness(matrix): + copy_of_img = deepcopy(matrix) + list = [] + for i in range(len(copy_of_img)): + for j in range(len(copy_of_img[i])): + if len(list) > 1: + for k in range(len(list)): + if (i, j) not in list[k] and copy_of_img[i][j] != 0: + list.append(check_sides(copy_of_img, i, j)) + else: + if copy_of_img[i][j] != 0: + list.append(check_sides(copy_of_img, i, j)) + + brigthness_list = [] + sum = 0 + for i in range(len(list)): + brigthness_list.append(brigthness(list[i], matrix)) + brigthness_list.sort(reverse = True) + print(brigthness_list) + + for i in list: + print(brigthness(i, matrix), i[randint(0, len(i) - 1)]) \ No newline at end of file diff --git a/homeworks/24_Simeon_Hristov/02_num_ways.py b/homeworks/24_Simeon_Hristov/02_num_ways.py new file mode 100644 index 0000000..756e64c --- /dev/null +++ b/homeworks/24_Simeon_Hristov/02_num_ways.py @@ -0,0 +1,8 @@ +def fibonacci_number(n): + if n <= 1: + return n + return fibonacci_number(n - 1) + fibonacci_number(n-2) + +def num_ways(n): + return fibonacci_number(n + 1) + diff --git a/homeworks/24_Simeon_Hristov/02_replace.py b/homeworks/24_Simeon_Hristov/02_replace.py new file mode 100644 index 0000000..c1e09e7 --- /dev/null +++ b/homeworks/24_Simeon_Hristov/02_replace.py @@ -0,0 +1,16 @@ +from copy import deepcopy +def replace_recursion(list, find, replace): + for i in range(len(list)): + if list[i] is find: + list[i] = replace + try: + if len(list[i]) and not isinstance(list[i], str): + list[i] = replace_recursion(list[i], find, replace) + except: + pass + return list + +def replace(list, find, replace): + list_cpy = deepcopy(list) + list_cpy = replace_recursion(list_cpy, find, replace) + return list_cpy