Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add homework 2 #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions homeworks/24_Simeon_Hristov/01_check_circles.py
Original file line number Diff line number Diff line change
@@ -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"
65 changes: 65 additions & 0 deletions homeworks/24_Simeon_Hristov/02_avg_brigthness.py
Original file line number Diff line number Diff line change
@@ -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)])
8 changes: 8 additions & 0 deletions homeworks/24_Simeon_Hristov/02_num_ways.py
Original file line number Diff line number Diff line change
@@ -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)

16 changes: 16 additions & 0 deletions homeworks/24_Simeon_Hristov/02_replace.py
Original file line number Diff line number Diff line change
@@ -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