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
4 changes: 3 additions & 1 deletion deprecated_tests/sem01/tests/test_lesson04_tasks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest
import random

import pytest

from solutions.sem01.lesson04.task1 import is_arithmetic_progression
from solutions.sem01.lesson04.task2 import merge_intervals
from solutions.sem01.lesson04.task3 import find_single_number
from solutions.sem01.lesson04.task4 import move_zeros_to_end
from solutions.sem01.lesson04.task5 import find_row_with_most_ones
from solutions.sem01.lesson04.task6 import count_cycles


@pytest.mark.parametrize("lst, expected", [
pytest.param([], True, id="empty_list"),
pytest.param([5], True, id="single_element"),
Expand Down
3 changes: 2 additions & 1 deletion deprecated_tests/sem01/tests/test_lesson05_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pytest
import pytest

from solutions.sem01.lesson05.task1 import is_palindrome
from solutions.sem01.lesson05.task2 import are_anagrams
Expand All @@ -7,6 +7,7 @@
from solutions.sem01.lesson05.task5 import reg_validator
from solutions.sem01.lesson05.task6 import simplify_path


@pytest.mark.parametrize("s, expected", [
pytest.param("", True, id="empty_string"),
pytest.param("a", True, id="single_char"),
Expand Down
3 changes: 2 additions & 1 deletion deprecated_tests/sem01/tests/test_lesson06_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pytest
import pytest

from solutions.sem01.lesson06.task1 import int_to_roman
from solutions.sem01.lesson06.task2 import get_len_of_longest_substring
Expand Down Expand Up @@ -88,6 +88,7 @@ def test_is_there_any_good_subarray(nums, k, expected):

import pytest


@pytest.mark.parametrize("text, expected", [
pytest.param("", 0, id="empty_string"),
pytest.param(" ", 0, id="only_spaces"),
Expand Down
2 changes: 1 addition & 1 deletion deprecated_tests/sem01/tests/test_lesson08_tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
import math
import time

from solutions.sem01.lesson08.task1 import make_averager
from solutions.sem01.lesson08.task2 import collect_statistic


def test_make_averager():
get_avg = make_averager(2)

Expand Down
3 changes: 1 addition & 2 deletions deprecated_tests/sem01/tests/test_lesson11_tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest

import math
import sys
from io import StringIO

import pytest

from solutions.sem01.lesson11.task1 import Vector2D

Expand Down
11 changes: 4 additions & 7 deletions deprecated_tests/sem01/tests_hw/test_hw1_tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import pytest
import uuid
from unittest.mock import MagicMock, patch, Mock
from unittest.mock import MagicMock, Mock, patch

import pytest

from homeworks.sem01.hw1.aggregate_segmentation import aggregate_segmentation, ALLOWED_TYPES
from homeworks.sem01.hw1.aggregate_segmentation import ALLOWED_TYPES, aggregate_segmentation
from homeworks.sem01.hw1.backoff import backoff
from homeworks.sem01.hw1.cache import lru_cache
from homeworks.sem01.hw1.convert_exception import convert_exceptions_to_api_compitable_ones
from .hw1_test_data.cache_test_data import (
TESTCASE_DATA,
TESTCASE_IDS,
)

NAME_BACKOFF_MODULE = "homeworks.hw1.backoff" # название модуля с backoff

Expand Down
2 changes: 0 additions & 2 deletions homeworks/sem01/hw1/backoff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from random import uniform
from time import sleep
from typing import (
Callable,
ParamSpec,
Expand Down
2 changes: 1 addition & 1 deletion solutions/sem01/lesson02/task3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def get_amount_of_ways_to_climb(stair_amount: int) -> int:
step_prev, step_curr = 1, 1
_step_prev, step_curr = 1, 1
# ваш код
return step_curr
2 changes: 1 addition & 1 deletion solutions/sem01/lesson03/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def flip_bits_in_range(num: int, left_bit: int, right_bit: int) -> int:
# ваш код
return num
return num
2 changes: 1 addition & 1 deletion solutions/sem01/lesson03/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def get_cube_root(n: float, eps: float) -> float:
# ваш код
return n
return n
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def is_arithmetic_progression(lst: list[list[int]]) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def merge_intervals(intervals: list[list[int, int]]) -> list[list[int, int]]:
# ваш код
return [[0,0]]
return [[0, 0]]
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def move_zeros_to_end(nums: list[int]) -> list[int]:
# ваш код
return 0
return 0
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def find_row_with_most_ones(matrix: list[list[int]]) -> int:
# ваш код
return 0
return 0
4 changes: 2 additions & 2 deletions solutions/sem01/lesson04/task6.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def count_cycles(arr: list[int]) -> int:
def count_cycles(arr: list[int]) -> int:
# ваш код
return 0
return 0
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def is_palindrome(text: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def are_anagrams(word1: str, word2: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def unzip(compress_text: str) -> str:
# ваш код
return compress_text
return compress_text
4 changes: 2 additions & 2 deletions solutions/sem01/lesson05/task5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def reg_validator(reg_expr: str, text: str) -> bool:
def reg_validator(reg_expr: str, text: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task6.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def simplify_path(path: str) -> str:
# ваш код
return path
return path
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def int_to_roman(num: int) -> str:
# ваш код
return ""
return ""
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def get_len_of_longest_substring(text: str) -> int:
# ваш код
return 0
return 0
1 change: 0 additions & 1 deletion solutions/sem01/lesson06/task3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ def is_there_any_good_subarray(
nums: list[int],
k: int,
) -> bool:

# ваш код
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def count_unique_words(text: str) -> int:
# ваш код
return 0
return 0
3 changes: 2 additions & 1 deletion solutions/sem01/lesson08/task1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Callable


def make_averager(accumulation_period: int) -> Callable[[float], float]:
# ваш код
pass
pass
8 changes: 3 additions & 5 deletions solutions/sem01/lesson08/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

T = TypeVar("T")

def collect_statistic(
statistics: dict[str, list[float, int]]
) -> Callable[[T], T]:


def collect_statistic(statistics: dict[str, list[float, int]]) -> Callable[[T], T]:
# ваш код
pass
pass
3 changes: 0 additions & 3 deletions solutions/sem01/lesson12/task3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys


class FileOut:
def __init__(
self,
Expand Down
22 changes: 13 additions & 9 deletions solutions/sem02/lesson03/task1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ class ShapeMismatchError(Exception):
pass


def sum_arrays_vectorized(
lhs: np.ndarray,
rhs: np.ndarray,
) -> np.ndarray: ...
def sum_arrays_vectorized(lhs: np.ndarray, rhs: np.ndarray) -> np.ndarray:
if len(lhs) != len(rhs):
raise ShapeMismatchError
return np.add(lhs, rhs)


def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray: ...
def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray:
return 3 * (abscissa**2) + 2 * abscissa + 1


def get_mutual_l2_distances_vectorized(
lhs: np.ndarray,
rhs: np.ndarray,
) -> np.ndarray: ...
def get_mutual_l2_distances_vectorized(lhs: np.ndarray, rhs: np.ndarray) -> np.ndarray:
if lhs.shape[1] != rhs.shape[1]:
raise ShapeMismatchError

cube = lhs[:, np.newaxis, :] - rhs[np.newaxis, :, :]
distances = np.sqrt(np.sum(cube**2, axis=2))
return distances
21 changes: 19 additions & 2 deletions solutions/sem02/lesson03/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ def convert_from_sphere(
distances: np.ndarray,
azimuth: np.ndarray,
inclination: np.ndarray,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ...
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
if not (distances.shape == azimuth.shape == inclination.shape):
raise ShapeMismatchError

x = distances * np.sin(inclination) * np.cos(azimuth)
y = distances * np.sin(inclination) * np.sin(azimuth)
z = distances * np.cos(inclination)

return x, y, z


def convert_to_sphere(
abscissa: np.ndarray,
ordinates: np.ndarray,
applicates: np.ndarray,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ...
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
if not (abscissa.shape == ordinates.shape == applicates.shape):
raise ShapeMismatchError

rad = np.sqrt(abscissa**2 + ordinates**2 + applicates**2)
azim = np.arctan2(ordinates, abscissa)
inc = np.arccos(applicates / rad)
inc = np.where(rad == 0, 0.0, inc)

return rad, azim, inc
15 changes: 14 additions & 1 deletion solutions/sem02/lesson03/task3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@

def get_extremum_indices(
ordinates: np.ndarray,
) -> tuple[np.ndarray, np.ndarray]: ...
) -> tuple[np.ndarray, np.ndarray]:
if ordinates.ndim > 1 or len(ordinates) < 3:
raise ValueError

left = ordinates[:-2]
center = ordinates[1:-1]
right = ordinates[2:]

max = (left < center) & (center > right)
min = (left > center) & (center < right)

index = np.arange(1, len(ordinates) - 1)

return index[min], index[max]
33 changes: 29 additions & 4 deletions solutions/sem02/lesson04/task1.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import numpy as np
from matplotlib import image


def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray:
# ваш код
return image
H, W = image.shape[:2]

if pad_size < 1:
raise ValueError

if image.ndim == 2:
zer = np.zeros((H + 2 * pad_size, W + 2 * pad_size), dtype=image.dtype)
zer[pad_size : pad_size + H, pad_size : pad_size + W] = image
else:
zer = np.zeros((H + 2 * pad_size, W + 2 * pad_size, image.shape[2]), dtype=image.dtype)
zer[pad_size : pad_size + H, pad_size : pad_size + W, :] = image

return zer


def blur_image(
image: np.ndarray,
kernel_size: int,
) -> np.ndarray:
# ваш код
return image
if kernel_size <= 0 or kernel_size % 2 == 0:
raise ValueError

if kernel_size == 1:
return image.copy()

padded_image = pad_image(image, kernel_size // 2)
res = np.zeros(image.shape, dtype=float)

for i in range(kernel_size):
for j in range(kernel_size):
res += padded_image[i : i + image.shape[0], j : j + image.shape[1]]

res /= kernel_size**2
return res.astype(np.uint8)


if __name__ == "__main__":
Expand Down
15 changes: 13 additions & 2 deletions solutions/sem02/lesson04/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ def get_dominant_color_info(
image: np.ndarray[np.uint8],
threshold: int = 5,
) -> tuple[np.uint8, float]:
# ваш код
if threshold < 1:
raise ValueError("threshold must be positive")

return 0, 0
img = image.astype(np.int64)
uniq, counts = np.unique(img, return_counts=True)
delta = uniq[:, np.newaxis] - uniq
res = np.abs(delta) < threshold
result = np.sum(res * counts, axis=1)
index = np.argmax(result)

color = uniq[index]
percentage = result[index] / image.size

return np.uint8(color), float(percentage)
11 changes: 10 additions & 1 deletion solutions/sem02/lesson05/task1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ def can_satisfy_demand(
costs: np.ndarray,
resource_amounts: np.ndarray,
demand_expected: np.ndarray,
) -> bool: ...
) -> bool:
if costs.shape[0] != len(resource_amounts):
raise ShapeMismatchError()
if costs.shape[1] != len(demand_expected):
raise ShapeMismatchError()

matrix = costs @ demand_expected
answer = (matrix <= resource_amounts).all()

return answer
Loading
Loading