diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 000000000..916dae4e4 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\Users\\Matvey\\gcc\\bin\\gcc.exe", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "windows-gcc-x64", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c20e25e03 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "C_Cpp.errorSquiggles": "enabled" +} \ No newline at end of file diff --git a/homeworks/sem01/hw1/aggregate_segmentation.py b/homeworks/sem01/hw1/aggregate_segmentation.py index 1cdc176af..62117ddd0 100644 --- a/homeworks/sem01/hw1/aggregate_segmentation.py +++ b/homeworks/sem01/hw1/aggregate_segmentation.py @@ -4,7 +4,6 @@ "voice_bot", } - def aggregate_segmentation( segmentation_data: list[dict[str, str | float | None]], ) -> tuple[dict[str, dict[str, dict[str, str | float]]], list[str]]: @@ -24,5 +23,80 @@ def aggregate_segmentation( Список `audio_id` (str), которые требуют переразметки. """ - # ваш код - return {}, [] + valid_data = {} + audio_ids_with_errors = tuple() + segment_cache = {} + + + + for segment in segmentation_data: + + if "segment_id" not in segment or segment["segment_id"] is None: + continue + + if "audio_id" not in segment or segment["audio_id"] is None: + continue + + audio_id = segment["audio_id"] + segment_id = segment["segment_id"] + + + is_valid = True + + + if not isinstance(segment_id, str): + is_valid = False + if not isinstance(audio_id, str): + is_valid = False + + + type_val = segment.get("type") + start_val = segment.get("segment_start") + end_val = segment.get("segment_end") + + none_count = 0 + for i in [type_val, start_val, end_val]: + if i is None: + none_count += 1 + + if none_count == 1 or none_count == 2: + + is_valid = False + elif none_count == 0: + + if not isinstance(type_val, str): + is_valid = False + elif type_val not in ALLOWED_TYPES: + is_valid = False + + if not isinstance(start_val, float): + is_valid = False + if not isinstance(end_val, float): + is_valid = False + + + if not is_valid: + audio_ids_with_errors = tuple(list(audio_ids_with_errors) + [audio_id]) + else: + if none_count == 0: + if audio_id not in valid_data: + valid_data[audio_id] = {} + + valid_data[audio_id][segment_id] = { + "start": start_val, + "end": end_val, + "type": type_val + } + elif none_count == 3: + if audio_id not in valid_data: + valid_data[audio_id] = {} + + + + + for audio_id in list(valid_data.keys()): + if audio_id in audio_ids_with_errors: + del valid_data[audio_id] + + + return valid_data, audio_ids_with_errors diff --git a/homeworks/sem01/hw1/backoff.py b/homeworks/sem01/hw1/backoff.py index 696ffa73a..ed2c0c9af 100644 --- a/homeworks/sem01/hw1/backoff.py +++ b/homeworks/sem01/hw1/backoff.py @@ -34,5 +34,47 @@ def backoff( ValueError, если были переданы невозможные аргументы. """ - # ваш код - pass + if retry_amount < 1 or retry_amount > 100: + raise ValueError("retry_amount должен быть в диапазоне от 1 до 100") + + if timeout_start <= 0 or timeout_start >= 10: + raise ValueError("timeout_start должен быть в диапазоне (0, 10)") + + if timeout_max <= 0 or timeout_max >= 10: + raise ValueError("timeout_max должен быть в диапазоне (0, 10)") + + if backoff_scale <= 0 or backoff_scale >= 10: + raise ValueError("backoff_scale должен быть в диапазоне (0, 10)") + + if not backoff_triggers: + raise ValueError("backoff_triggers не может быть пустым") + + def decorator(func: Callable[P, R]) -> Callable[P, R]: + def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: + last_exception = None + current_timeout = timeout_start + + for trying in range(retry_amount): + try: + return func(*args, **kwargs) + except Exception as e: + last_exception = e + + should_retry = any(isinstance(e, trigger) for trigger in backoff_triggers) + + if not should_retry or trying == retry_amount - 1: + + raise last_exception + + jitter = uniform(0, 0.5) + total_sleep_time = min(current_timeout + jitter, timeout_max) + + sleep(total_sleep_time) + + current_timeout = min(current_timeout * backoff_scale, timeout_max) + + raise last_exception + + return wrapper + + return decorator \ No newline at end of file diff --git a/homeworks/sem01/hw1/cache.py b/homeworks/sem01/hw1/cache.py index 9eb1d5d2d..573317439 100644 --- a/homeworks/sem01/hw1/cache.py +++ b/homeworks/sem01/hw1/cache.py @@ -23,5 +23,70 @@ def lru_cache(capacity: int) -> Callable[[Callable[P, R]], Callable[P, R]]: для получения целого числа. ValueError, если после округления capacity - число, меньшее 1. """ - # ваш код - pass + try: + capacity = round(capacity) + except (TypeError, ValueError) as e: + raise TypeError + + if capacity < 1: + raise ValueError + + def decorator(func: Callable[P, R]) -> Callable[P, R]: + class Node: + def __init__(self, key, value): + self.key = key + self.value = value + self.prev = None + self.next = None + + cache = {} + head = Node(None, None) + tail = Node(None, None) + head.next = tail + tail.prev = head + + def remove_node(node: Node): + """Удаляет узел из двусвязного списка""" + prev_node = node.prev + next_node = node.next + prev_node.next = next_node + next_node.prev = prev_node + + def add_to_front(node: Node): + """Добавляет узел в начало списка (после head)""" + first_node = head.next + head.next = node + node.prev = head + node.next = first_node + first_node.prev = node + + def move_to_front(node: Node): + """Перемещает узел в начало списка""" + remove_node(node) + add_to_front(node) + + def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: + key = (args, tuple(sorted(kwargs.items()))) + + if key in cache: + node = cache[key] + move_to_front(node) + return node.value + else: + result = func(*args, **kwargs) + + new_node = Node(key, result) + + if len(cache) >= capacity: + lru_node = tail.prev + remove_node(lru_node) + del cache[lru_node.key] + + add_to_front(new_node) + cache[key] = new_node + + return result + + return wrapper + + return decorator \ No newline at end of file diff --git a/homeworks/sem01/hw1/convert_exception.py b/homeworks/sem01/hw1/convert_exception.py index fe5c770fd..8626ead53 100644 --- a/homeworks/sem01/hw1/convert_exception.py +++ b/homeworks/sem01/hw1/convert_exception.py @@ -24,5 +24,17 @@ def convert_exceptions_to_api_compitable_ones( Декоратор для непосредственного использования. """ - # ваш код - pass + def decorator(func: Callable[P, R]) -> Callable[P, R]: + def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: + try: + return func(*args, **kwargs) + except Exception as e: + for exception_type, api_exception in exception_to_api_exception.items(): + if isinstance(e, exception_type): + raise api_exception() + + raise + + return wrapper + + return decorator \ No newline at end of file diff --git a/homeworks/sem01/hw1/test_segmentation.py b/homeworks/sem01/hw1/test_segmentation.py new file mode 100644 index 000000000..a88237c01 --- /dev/null +++ b/homeworks/sem01/hw1/test_segmentation.py @@ -0,0 +1,146 @@ +ALLOWED_TYPES = { + "spotter_word", + "voice_human", + "voice_bot", +} + +def aggregate_segmentation( + segmentation_data: list[dict[str, str | float | None]], +) -> tuple[dict[str, dict[str, dict[str, str | float]]], list[str]]: + """ + Функция для валидации и агрегации данных разметки аудио сегментов. + + Args: + segmentation_data: словарь, данные разметки аудиосегментов с полями: + "audio_id" - уникальный идентификатор аудио. + "segment_id" - уникальный идентификатор сегмента. + "segment_start" - время начала сегмента. + "segment_end" - время окончания сегмента. + "type" - тип голоса в сегменте. + + Returns: + Словарь с валидными сегментами, объединёнными по `audio_id`; + Список `audio_id` (str), которые требуют переразметки. + """ + + valid_data = {} + audio_ids_with_errors = tuple() + segment_cache = {} + + + + for segment in segmentation_data: + + if "segment_id" not in segment or segment["segment_id"] is None: + continue + + if "audio_id" not in segment or segment["audio_id"] is None: + continue + + audio_id = segment["audio_id"] + segment_id = segment["segment_id"] + + + is_valid = True + + + if not isinstance(segment_id, str): + is_valid = False + if not isinstance(audio_id, str): + is_valid = False + + + type_val = segment.get("type") + start_val = segment.get("segment_start") + end_val = segment.get("segment_end") + + none_count = 0 + for i in [type_val, start_val, end_val]: + if i is None: + none_count += 1 + + if none_count == 1 or none_count == 2: + + is_valid = False + elif none_count == 0: + + if not isinstance(type_val, str): + is_valid = False + elif type_val not in ALLOWED_TYPES: + is_valid = False + + if not isinstance(start_val, float): + is_valid = False + if not isinstance(end_val, float): + is_valid = False + + + if not is_valid: + audio_ids_with_errors = tuple(list(audio_ids_with_errors) + [audio_id]) + else: + if none_count == 0: + if audio_id not in valid_data: + valid_data[audio_id] = {} + + valid_data[audio_id][segment_id] = { + "start": start_val, + "end": end_val, + "type": type_val + } + elif none_count == 3: + if audio_id not in valid_data: + valid_data[audio_id] = {} + + + + + for audio_id in list(valid_data.keys()): + if audio_id in audio_ids_with_errors: + del valid_data[audio_id] + + + return valid_data, audio_ids_with_errors + + +def test_aggregate_segmentation_with_invalid_type_after_valid_detailed(): + """Тест с дополнительными проверками состояния до и после невалидного сегмента""" + segmentation_data = [ + { + "audio_id": "audio_1", + "segment_id": "segment_1", + "segment_start": 0.0, + "segment_end": 1.0, + "type": "voice_human" + }, + { + "audio_id": "audio_2", # Другой валидный audio_id + "segment_id": "segment_3", + "segment_start": 0.0, + "segment_end": 1.0, + "type": "voice_bot" + }, + { + "audio_id": "audio_1", # Невалидный сегмент + "segment_id": "segment_2", + "segment_start": 1.0, + "segment_end": 2.0, + "type": "invalid_type" + } + ] + + valid_result, invalid_result = aggregate_segmentation(segmentation_data) + + # audio_1 должен быть в невалидных + assert "audio_1" in invalid_result + # audio_1 не должно быть в валидных + assert "audio_1" not in valid_result + # audio_2 должен остаться валидным + assert "audio_2" in valid_result + # В audio_2 должен быть один сегмент + assert len(valid_result["audio_2"]) == 1 + # Проверяем содержимое сегмента audio_2 + assert valid_result["audio_2"]["segment_3"] == { + "start": 0.0, + "end": 1.0, + "type": "voice_bot" + } \ No newline at end of file diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/query/client-vscode/query.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/query/client-vscode/query.json new file mode 100644 index 000000000..82bb96424 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/query/client-vscode/query.json @@ -0,0 +1 @@ +{"requests":[{"kind":"cache","version":2},{"kind":"codemodel","version":2},{"kind":"toolchains","version":1},{"kind":"cmakeFiles","version":1}]} \ No newline at end of file diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-13T18-38-03-0559.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-13T18-38-03-0559.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-13T18-38-03-0559.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T12-28-49-0106.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T12-28-49-0106.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T12-28-49-0106.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-08-20-0354.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-08-20-0354.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-08-20-0354.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-43-41-0618.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-43-41-0618.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-43-41-0618.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-49-20-0252.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-49-20-0252.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-14T20-49-20-0252.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T08-33-39-0670.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T08-33-39-0670.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T08-33-39-0670.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-18-59-0647.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-18-59-0647.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-18-59-0647.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-38-16-0304.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-38-16-0304.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T09-38-16-0304.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-01-37-0424.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-01-37-0424.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-01-37-0424.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-57-19-0060.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-57-19-0060.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-15T10-57-19-0060.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T12-57-48-0090.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T12-57-48-0090.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T12-57-48-0090.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T13-31-38-0525.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T13-31-38-0525.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T13-31-38-0525.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T15-45-19-0012.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T15-45-19-0012.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T15-45-19-0012.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T18-15-15-0126.json b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T18-15-15-0126.json new file mode 100644 index 000000000..27bf3c2c5 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/.cmake/api/v1/reply/error-2025-11-20T18-15-15-0126.json @@ -0,0 +1,70 @@ +{ + "cmake" : + { + "generator" : + { + "multiConfig" : false, + "name" : "NMake Makefiles" + }, + "paths" : + { + "cmake" : "C:/Program Files/CMake/bin/cmake.exe", + "cpack" : "C:/Program Files/CMake/bin/cpack.exe", + "ctest" : "C:/Program Files/CMake/bin/ctest.exe", + "root" : "C:/Program Files/CMake/share/cmake-4.1" + }, + "version" : + { + "isDirty" : false, + "major" : 4, + "minor" : 1, + "patch" : 2, + "string" : "4.1.2", + "suffix" : "" + } + }, + "objects" : [], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + }, + { + "kind" : "cmakeFiles", + "version" : 1 + } + ], + "responses" : + [ + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + }, + { + "error" : "no buildsystem generated" + } + ] + } + } + } +} diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeCache.txt b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeCache.txt new file mode 100644 index 000000000..aa8f3d4ec --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeCache.txt @@ -0,0 +1,115 @@ +# This is the CMakeCache file. +# For build in directory: d:/VSprojects/python_mipt_dafe_tasks/out/build/GCC 15.2.0 x86_64-w64-mingw32 +# It was generated by CMake: C:/Program Files/CMake/bin/cmake.exe +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//No help, variable specified on the command line. +CMAKE_BUILD_TYPE:UNINITIALIZED=Debug + +//No help, variable specified on the command line. +CMAKE_CXX_COMPILER:UNINITIALIZED=C:/Users/Matvey/gcc/bin/g++.exe + +//No help, variable specified on the command line. +CMAKE_C_COMPILER:UNINITIALIZED=C:/Users/Matvey/gcc/bin/gcc.exe + +//Value Computed by CMake. +CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=D:/VSprojects/python_mipt_dafe_tasks/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/pkgRedirects + +//No help, variable specified on the command line. +CMAKE_INSTALL_PREFIX:UNINITIALIZED=D:/VSprojects/python_mipt_dafe_tasks/out/install/GCC 15.2.0 x86_64-w64-mingw32 + +//Program used to build from makefiles. +CMAKE_MAKE_PROGRAM:STRING=nmake + +//Value Computed by CMake +CMAKE_PROJECT_COMPAT_VERSION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=main + +//Value Computed by CMake +CMAKE_PROJECT_VERSION:STATIC=0.1.0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MAJOR:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MINOR:STATIC=1 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_PATCH:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_TWEAK:STATIC= + +//Value Computed by CMake +main_BINARY_DIR:STATIC=D:/VSprojects/python_mipt_dafe_tasks/out/build/GCC 15.2.0 x86_64-w64-mingw32 + +//Value Computed by CMake +main_IS_TOP_LEVEL:STATIC=ON + +//Value Computed by CMake +main_SOURCE_DIR:STATIC=D:/VSprojects/python_mipt_dafe_tasks + + +######################## +# INTERNAL cache entries +######################## + +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=d:/VSprojects/python_mipt_dafe_tasks/out/build/GCC 15.2.0 x86_64-w64-mingw32 +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=4 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=1 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake.exe +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cpack.exe +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=C:/Program Files/CMake/bin/ctest.exe +//Path to cache edit program executable. +CMAKE_EDIT_COMMAND:INTERNAL=C:/Program Files/CMake/bin/cmake-gui.exe +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=NMake Makefiles +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=D:/VSprojects/python_mipt_dafe_tasks +//Name of CMakeLists files to read +CMAKE_LIST_FILE_NAME:INTERNAL=CMakeLists.txt +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=C:/Program Files/CMake/share/cmake-4.1 + diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/4.1.2/CMakeSystem.cmake b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/4.1.2/CMakeSystem.cmake new file mode 100644 index 000000000..909db20dc --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/4.1.2/CMakeSystem.cmake @@ -0,0 +1,15 @@ +set(CMAKE_HOST_SYSTEM "Windows-10.0.19045") +set(CMAKE_HOST_SYSTEM_NAME "Windows") +set(CMAKE_HOST_SYSTEM_VERSION "10.0.19045") +set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64") + + + +set(CMAKE_SYSTEM "Windows-10.0.19045") +set(CMAKE_SYSTEM_NAME "Windows") +set(CMAKE_SYSTEM_VERSION "10.0.19045") +set(CMAKE_SYSTEM_PROCESSOR "AMD64") + +set(CMAKE_CROSSCOMPILING "FALSE") + +set(CMAKE_SYSTEM_LOADED 1) diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/CMakeConfigureLog.yaml b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/CMakeConfigureLog.yaml new file mode 100644 index 000000000..f36e049ca --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/CMakeConfigureLog.yaml @@ -0,0 +1,143 @@ + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... + +--- +events: + - + kind: "message-v1" + backtrace: + - "C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeDetermineSystem.cmake:212 (message)" + - "CMakeLists.txt:2 (project)" + message: | + The system is: Windows - 10.0.19045 - AMD64 +... diff --git a/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/cmake.check_cache b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/cmake.check_cache new file mode 100644 index 000000000..3dccd7317 --- /dev/null +++ b/out/build/GCC 15.2.0 x86_64-w64-mingw32/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/solutions/lesson12/Untitled-1.ipynb b/solutions/lesson12/Untitled-1.ipynb new file mode 100644 index 000000000..577d1ac67 --- /dev/null +++ b/solutions/lesson12/Untitled-1.ipynb @@ -0,0 +1,21 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "5aff5433", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"abs\")" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/solutions/lesson12/test.ipynb b/solutions/lesson12/test.ipynb new file mode 100644 index 000000000..aa26163ba --- /dev/null +++ b/solutions/lesson12/test.ipynb @@ -0,0 +1,23 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "572ff116", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/solutions/sem01/lesson02/task1.py b/solutions/sem01/lesson02/task1.py index c782dcd88..188725c2d 100644 --- a/solutions/sem01/lesson02/task1.py +++ b/solutions/sem01/lesson02/task1.py @@ -1,4 +1,4 @@ -def get_factorial(num: int) -> int: - factorial = 1 - # ваш код - return factorial +import sys + +# Print the full path of the Python interpreter +print(sys.executable) \ No newline at end of file diff --git a/solutions/sem01/lesson02/task2.py b/solutions/sem01/lesson02/task2.py index b91420c56..4b62c789c 100644 --- a/solutions/sem01/lesson02/task2.py +++ b/solutions/sem01/lesson02/task2.py @@ -1,4 +1,5 @@ def get_doubled_factorial(num: int) -> int: factorial = 1 - # ваш код - return factorial + for i in range(num, 1, -2): + factorial = factorial*i + return factorial \ No newline at end of file diff --git a/solutions/sem01/lesson02/task3.py b/solutions/sem01/lesson02/task3.py index ee2a84ecf..bb9b907bc 100644 --- a/solutions/sem01/lesson02/task3.py +++ b/solutions/sem01/lesson02/task3.py @@ -1,4 +1,10 @@ def get_amount_of_ways_to_climb(stair_amount: int) -> int: step_prev, step_curr = 1, 1 - # ваш код - return step_curr + + for i in range(1, stair_amount): + fixing = step_curr + step_curr = step_curr+step_prev + step_prev = fixing + + + return step_curr \ No newline at end of file diff --git a/solutions/sem01/lesson02/task4.py b/solutions/sem01/lesson02/task4.py index 45ff4bb42..7c91fe1e9 100644 --- a/solutions/sem01/lesson02/task4.py +++ b/solutions/sem01/lesson02/task4.py @@ -1,4 +1,10 @@ def get_multiplications_amount(num: int) -> int: multiplications_amount = 0 - # ваш код - return multiplications_amount + + while num//2!=0: + if num%2 == 1: + multiplications_amount+=1 + num -= 1 + num = num//2 + multiplications_amount+=1 + return multiplications_amount \ No newline at end of file diff --git a/solutions/sem01/lesson02/task5.py b/solutions/sem01/lesson02/task5.py index 8fb9a048d..dc8989177 100644 --- a/solutions/sem01/lesson02/task5.py +++ b/solutions/sem01/lesson02/task5.py @@ -1,3 +1,9 @@ def get_gcd(num1: int, num2: int) -> int: - # ваш код - return num1 + while num1 != 0 and num2 != 0: + if num1 > num2: + num1 = num1 % num2 + else: + num2 = num2 % num1 + + + return(num1+num2) diff --git a/solutions/sem01/lesson02/task6.py b/solutions/sem01/lesson02/task6.py index bec4b6cd9..5ac277de0 100644 --- a/solutions/sem01/lesson02/task6.py +++ b/solutions/sem01/lesson02/task6.py @@ -1,4 +1,14 @@ def get_sum_of_prime_divisors(num: int) -> int: - sum_of_divisors = 0 - # ваш код - return sum_of_divisors + sum_of_divisors = 0 + divisor = 2 + while divisor <= num: + simple = True + if num % divisor == 0: + + for i in range(2, divisor): + if divisor%i == 0: + simple = False + if simple: + sum_of_divisors += divisor + divisor += 1 + return sum_of_divisors \ No newline at end of file diff --git a/solutions/sem01/lesson02/task7.py b/solutions/sem01/lesson02/task7.py index 4b2d73beb..9fc3cf393 100644 --- a/solutions/sem01/lesson02/task7.py +++ b/solutions/sem01/lesson02/task7.py @@ -1,5 +1,10 @@ def is_palindrome(num: int) -> bool: num_reversed = 0 num_origin = num - # ваш код - return num_origin == num_reversed + + while num > 0: + digit = num % 10 + num_reversed = num_reversed * 10 + digit + num = num // 10 + + return num_origin == num_reversed \ No newline at end of file diff --git a/solutions/sem01/lesson03/task1.py b/solutions/sem01/lesson03/task1.py index f1d8fe26b..91b26cb60 100644 --- a/solutions/sem01/lesson03/task1.py +++ b/solutions/sem01/lesson03/task1.py @@ -1,3 +1,5 @@ def flip_bits_in_range(num: int, left_bit: int, right_bit: int) -> int: - # ваш код - return num \ No newline at end of file + maska = ((1 << right_bit) - 1) ^ ((1 << (left_bit - 1)) - 1) + + return num^maska #Макаров Матвей 514 + diff --git a/solutions/sem01/lesson03/task2.py b/solutions/sem01/lesson03/task2.py index a3a738c2a..ba4dd56ad 100644 --- a/solutions/sem01/lesson03/task2.py +++ b/solutions/sem01/lesson03/task2.py @@ -1,3 +1,15 @@ def get_cube_root(n: float, eps: float) -> float: - # ваш код - return n \ No newline at end of file + sign = 1 + if n < 0: + n = abs(n) + sign = -1 + + root = n / 2 + + while abs(root**3 - n) >= eps: + if root**3 > n: + root = root / 2 + elif root**3 < n: + root = root * 1.5 + + return root * sign #Макаров Матвей 514 diff --git a/solutions/sem01/lesson03/task3.py b/solutions/sem01/lesson03/task3.py index 5e91a6ac5..c46baafc1 100644 --- a/solutions/sem01/lesson03/task3.py +++ b/solutions/sem01/lesson03/task3.py @@ -1,3 +1,3 @@ def get_nth_digit(num: int) -> int: - # ваш код - return 0 + + return int(str((num-1)*2)[0]) #Макаров Матвей 514 \ No newline at end of file diff --git a/solutions/sem01/lesson04/task1.py b/solutions/sem01/lesson04/task1.py index 47384423a..0a3bd0d10 100644 --- a/solutions/sem01/lesson04/task1.py +++ b/solutions/sem01/lesson04/task1.py @@ -1,3 +1,9 @@ def is_arithmetic_progression(lst: list[list[int]]) -> bool: - # ваш код - return False \ No newline at end of file + lst = sorted(lst) + ok = True + for i in range(len(lst)-2): + if lst[i] - lst[i+1] != lst[i+1] - lst[i+2]: + ok = False + break + + return ok diff --git a/solutions/sem01/lesson04/task2.py b/solutions/sem01/lesson04/task2.py index 4591d0a3e..f918a8f9c 100644 --- a/solutions/sem01/lesson04/task2.py +++ b/solutions/sem01/lesson04/task2.py @@ -1,3 +1,14 @@ def merge_intervals(intervals: list[list[int, int]]) -> list[list[int, int]]: - # ваш код - return [[0,0]] \ No newline at end of file + intervals = sorted(intervals) + intervals.append([-2, -1]) + res = [] + for i in range(len(intervals)-1): + if intervals[i][1]>=intervals[i+1][0] and intervals[i][1]=intervals[i+1][1]: + intervals[i+1] = intervals[i] + + else: + res.append(intervals[i]) + return res diff --git a/solutions/sem01/lesson04/task3.py b/solutions/sem01/lesson04/task3.py index 7253f6cbd..89e58fdf8 100644 --- a/solutions/sem01/lesson04/task3.py +++ b/solutions/sem01/lesson04/task3.py @@ -1,3 +1,6 @@ -def find_single_number(nums: list[int]) -> int: - # ваш код - return 0 +def find_single_number(nums: list[int]) -> int: + res = 0 + + for i in range(len(nums)): + res = res ^ nums[i] + return res diff --git a/solutions/sem01/lesson04/task4.py b/solutions/sem01/lesson04/task4.py index b21bc5a39..3b80843c7 100644 --- a/solutions/sem01/lesson04/task4.py +++ b/solutions/sem01/lesson04/task4.py @@ -1,3 +1,11 @@ def move_zeros_to_end(nums: list[int]) -> list[int]: - # ваш код - return 0 \ No newline at end of file + count= 0 #можно ли назвать переменную "K" и в комментарии указать, что она значит? + #или желательно все переменные называть по их предназначению? + for i in range(len(nums)): + if nums[i] != 0: + nums[count], nums[i] = nums[i], nums[count] + count+=1 + + + return count + diff --git a/solutions/sem01/lesson04/task5.py b/solutions/sem01/lesson04/task5.py index 02d7742bb..63a23e0aa 100644 --- a/solutions/sem01/lesson04/task5.py +++ b/solutions/sem01/lesson04/task5.py @@ -1,3 +1,16 @@ def find_row_with_most_ones(matrix: list[list[int]]) -> int: - # ваш код - return 0 \ No newline at end of file + maxi = 0 + place = 0 + for i in range(len(matrix)): + matrix[i].reverse() # на семенаре reverse был + sumi = 0 + for j in range(len(matrix[i])): + if matrix[i][j] == 0: + break + sumi += 1 + + if sumi > maxi: + maxi = sumi + place = i + + return place diff --git a/solutions/sem01/lesson04/task6.py b/solutions/sem01/lesson04/task6.py index 16df27ca6..b7a17bbf4 100644 --- a/solutions/sem01/lesson04/task6.py +++ b/solutions/sem01/lesson04/task6.py @@ -1,3 +1,13 @@ def count_cycles(arr: list[int]) -> int: - # ваш код - return 0 \ No newline at end of file + cycle = 0 + for i in range(len(arr)): + if arr[i] != -1: + cycle += 1 + + element = arr[i] + while arr[element] != -1: + remember = arr[element] + arr[element] = -1 + element=remember + + return cycle diff --git a/solutions/sem01/lesson05/task1.py b/solutions/sem01/lesson05/task1.py index 9a17211e5..af4ca3248 100644 --- a/solutions/sem01/lesson05/task1.py +++ b/solutions/sem01/lesson05/task1.py @@ -1,3 +1,5 @@ def is_palindrome(text: str) -> bool: - # ваш код + text = text.lower() + if text == text[::-1]: + return True return False \ No newline at end of file diff --git a/solutions/sem01/lesson05/task2.py b/solutions/sem01/lesson05/task2.py index 367503802..c32c0aef0 100644 --- a/solutions/sem01/lesson05/task2.py +++ b/solutions/sem01/lesson05/task2.py @@ -1,3 +1,3 @@ def are_anagrams(word1: str, word2: str) -> bool: - # ваш код - return False \ No newline at end of file + + return sorted(word1)==sorted(word2) \ No newline at end of file diff --git a/solutions/sem01/lesson05/task3.py b/solutions/sem01/lesson05/task3.py index e368e2f49..94aa30b87 100644 --- a/solutions/sem01/lesson05/task3.py +++ b/solutions/sem01/lesson05/task3.py @@ -1,3 +1,8 @@ def is_punctuation(text: str) -> bool: - # ваш код - return False + alphabet = "!""#$%&'()*+,-./:;<=>?@[\]^_{|}~`" + if text == "": + return False + for sym in text: + if sym not in alphabet: + return False + return True diff --git a/solutions/sem01/lesson05/task4.py b/solutions/sem01/lesson05/task4.py index 4c4e9086e..a74948b32 100644 --- a/solutions/sem01/lesson05/task4.py +++ b/solutions/sem01/lesson05/task4.py @@ -1,3 +1,30 @@ def unzip(compress_text: str) -> str: - # ваш код - return compress_text \ No newline at end of file + text = "" + compress_text += " " + pul = "" + k=0 + for i in compress_text: + if i ==" " or i in "0123456789": + text += pul + pul = "" + k += 1 + continue + if i == "*": + ind = 1 + number = 0 + while compress_text[k+ind].isdigit() and k + ind bool: - # ваш код - return False \ No newline at end of file + i = 0 + r = 0 + + while r < len(reg_expr) and i < len(text): + symb = reg_expr[r] + + if symb == 'd': + if not text[i].isdigit(): + return False + while i < len(text) and text[i].isdigit(): + i += 1 + r += 1 + + elif symb == 'w': + if not text[i].isalpha(): + return False + while i < len(text) and text[i].isalpha(): + i += 1 + r += 1 + + elif symb == 's': + if not (text[i].isalpha() or text[i].isdigit()): + return False + while i < len(text) and (text[i].isalpha() or text[i].isdigit()): + i += 1 + r += 1 + + else: + if text[i] != symb: + return False + i += 1 + r += 1 + + return i == len(text) and r == len(reg_expr) diff --git a/solutions/sem01/lesson05/task6.py b/solutions/sem01/lesson05/task6.py index 1b914ada7..97bf37beb 100644 --- a/solutions/sem01/lesson05/task6.py +++ b/solutions/sem01/lesson05/task6.py @@ -1,3 +1,23 @@ def simplify_path(path: str) -> str: - # ваш код - return path \ No newline at end of file + components = path.split('/') + stuff = [] + + for comp in components: + if comp == '' or comp == '.': + continue + elif comp == '..': + if stuff != []: + stuff.pop() + else: + return "" + else: + stuff.append(comp) + + path = "/" + for i in range(len(stuff)): + path = path + stuff[i] + '/' + + if stuff == []: + return '/' + return path[:-1] + diff --git a/solutions/sem01/lesson06/task1.py b/solutions/sem01/lesson06/task1.py index 2d1e30e96..f204b65f9 100644 --- a/solutions/sem01/lesson06/task1.py +++ b/solutions/sem01/lesson06/task1.py @@ -1,3 +1,15 @@ def int_to_roman(num: int) -> str: - # ваш код - return "" \ No newline at end of file + rom_dict = { + 1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', + 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', + 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I' + } + + values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] + + res = [] + for value in values: + while num >= value: + res.append(rom_dict[value]) + num -= value + return ''.join(res) diff --git a/solutions/sem01/lesson06/task2.py b/solutions/sem01/lesson06/task2.py index f535b5a0c..4a0dc9d64 100644 --- a/solutions/sem01/lesson06/task2.py +++ b/solutions/sem01/lesson06/task2.py @@ -1,3 +1,11 @@ def get_len_of_longest_substring(text: str) -> int: - # ваш код - return 0 \ No newline at end of file + res = "" + maxi = 0 + for i in range(len(text)): + if text[i] not in res: + res += text[i] + else: + maxi = max(maxi, len(res)) + res = res[res.find(text[i])+1:] + text[i] + maxi = max(maxi, len(res)) + return maxi diff --git a/solutions/sem01/lesson06/task3.py b/solutions/sem01/lesson06/task3.py index 7449a1e72..75b5c1480 100644 --- a/solutions/sem01/lesson06/task3.py +++ b/solutions/sem01/lesson06/task3.py @@ -2,6 +2,25 @@ def is_there_any_good_subarray( nums: list[int], k: int, ) -> bool: + arr_ost = [0] + next_sum = 0 + + for i in range(len(nums)): + next_sum += nums[i] + ost = next_sum % k + + if ost in arr_ost: + print(arr_ost.index(ost), i, arr_ost) + if i - arr_ost.index(ost) >= 2: + return True + else: + arr_ost.append(ost) + + else: + arr_ost.append(ost) + + if (len(arr_ost) - 1) - arr_ost.index(arr_ost[-1]) >= 2: + return True - # ваш код return False + diff --git a/solutions/sem01/lesson06/task4.py b/solutions/sem01/lesson06/task4.py index 5b75a110c..beb59265f 100644 --- a/solutions/sem01/lesson06/task4.py +++ b/solutions/sem01/lesson06/task4.py @@ -1,3 +1,8 @@ def count_unique_words(text: str) -> int: - # ваш код - return 0 \ No newline at end of file + text = text.lower() + res = "" + for i in range(len(text)): + if (text[i] >= 'a' and text[i] <= 'z') or (text[i] >= '0' and text[i] <= '9') or text[i] == " ": + res += text[i] + + return len(set(res.split())) diff --git a/solutions/sem01/lesson08/task1.py b/solutions/sem01/lesson08/task1.py index 4390f6c84..5af0aaaf3 100644 --- a/solutions/sem01/lesson08/task1.py +++ b/solutions/sem01/lesson08/task1.py @@ -1,5 +1,12 @@ from typing import Callable def make_averager(accumulation_period: int) -> Callable[[float], float]: - # ваш код - pass \ No newline at end of file + values = [] + + def get_avg(value: float) -> float: + values.append(value) + if len(values) > accumulation_period: + values.pop(0) + return sum(values) / len(values) + + return get_avg \ No newline at end of file diff --git a/solutions/sem01/lesson08/task2.py b/solutions/sem01/lesson08/task2.py index 6e4af8707..87e72fa7c 100644 --- a/solutions/sem01/lesson08/task2.py +++ b/solutions/sem01/lesson08/task2.py @@ -1,3 +1,4 @@ +import time from typing import Callable, TypeVar T = TypeVar("T") @@ -5,6 +6,23 @@ def collect_statistic( statistics: dict[str, list[float, int]] ) -> Callable[[T], T]: + def decor(func: Calable) -> Callable: + @wraps(func) + def wrapper(*args, **kwargs): + start_time = time.time() + res = func(*args, **kwargs) + end_time = time.time() + + statistics.setdefault(func.__name__, [0, 0]) + count = statistics[func.__name__][1] + statistics[func.__name__][0] = count * statistics[func.__name__][0] + end_time - start_time + statistics[func.__name__][0] /= count + 1 + statistics[func.__name__][1] += 1 + + return res + + return wrapper + return decor # ваш код - pass \ No newline at end of file + pass diff --git a/solutions/sem01/lesson11/task1.py b/solutions/sem01/lesson11/task1.py index 6a15f31fb..255797f3a 100644 --- a/solutions/sem01/lesson11/task1.py +++ b/solutions/sem01/lesson11/task1.py @@ -1,10 +1,129 @@ +import math + class Vector2D: + + def conj(self) -> "Vector2D": # ваш код - return Vector2D() + return Vector2D(self.abscissa, (self.ordinate)*(-1)) def get_angle(self, other: "Vector2D") -> float: - # ваш код - return 0 + if isinstance(other, Vector2D): + if self == Vector2D() or other == Vector2D(): + raise ValueError + return math.acos((self @ other)/(abs(self)*abs(other))) + raise TypeError + + def __init__(self, abscissa: float = 0.0, ordinate: float = 0.0): + self._abscissa = float(abscissa) + self._ordinate = float(ordinate) + + @property + def abscissa(self) -> float: + return self._abscissa + + @property + def ordinate(self) -> float: + return self._ordinate + + def __repr__(self) -> str: + x = int(self._abscissa) if self._abscissa == int(self._abscissa) else self._abscissa + y = int(self._ordinate) if self._ordinate == int(self._ordinate) else self._ordinate + return f"Vector2D(abscissa={x}, ordinate={y})" + + def __eq__(self, other: 'Vector2D') -> bool: + if not isinstance(other, Vector2D): + return False + return (math.isclose(self.ordinate, other.ordinate) and math.isclose(self.abscissa, other.abscissa)) + + def __ne__(self, other: 'Vector2D') -> bool: + return not (self == other) + + def __lt__(self, other: 'Vector2D') -> bool: + if not isinstance(other, Vector2D): + return NotImplemented + if not math.isclose(self.abscissa, other.abscissa): + return self.abscissa < other.abscissa + elif not math.isclose(self.ordinate, other.ordinate): + return self.ordinate < other.ordinate + return False + + def __le__(self, other: 'Vector2D') -> bool: + if not isinstance(other, Vector2D): + return NotImplemented + return (self < other or self == other) + + def __gt__(self, other: 'Vector2D') -> bool: + if not isinstance(other, Vector2D): + return NotImplemented + if not math.isclose(self.abscissa, other.abscissa): + return self.abscissa > other.abscissa + elif not math.isclose(self.ordinate, other.ordinate): + return self.ordinate > other.ordinate + return False + + def __ge__(self, other: 'Vector2D') -> bool: + if not isinstance(other, Vector2D): + return NotImplemented + return (self > other or self == other) + + def __abs__(self) -> float: + return (self.abscissa**2 + self.ordinate**2)**0.5 + + def __bool__(self) -> bool: + return not (math.isclose(self.abscissa, 0) and math.isclose(self.ordinate, 0)) + + def __mul__(self, scalar: float): + if isinstance(scalar, Vector2D): + return NotImplemented + return Vector2D(self.abscissa * scalar, self.ordinate * scalar) + + def __rmul__(self, scalar: float): + if isinstance(scalar, Vector2D): + return NotImplemented + return Vector2D(self.abscissa * scalar, self.ordinate * scalar) + + def __truediv__(self, scalar: float): + return Vector2D(self.abscissa / scalar, self.ordinate / scalar) + + def __add__(self, other): + if isinstance(other, Vector2D): + return Vector2D(round(self.abscissa + other.abscissa, 5), round(self.ordinate + other.ordinate, 5)) + return Vector2D(round(self.abscissa + other, 5), round(self.ordinate + other, 5)) + + def __radd__(self, other): + if isinstance(other, Vector2D): + return Vector2D(round(self.abscissa + other.abscissa, 5), round(self.ordinate + other.ordinate, 5)) + if isinstance(other, (int, float)): + return Vector2D(round(self.abscissa + other, 5), round(self.ordinate + other, 5)) + return NotImplemented + + def __sub__(self, other): + if isinstance(other, Vector2D): + return Vector2D(round(self.abscissa - other.abscissa, 5), round(self.ordinate - other.ordinate, 5)) + if isinstance(other, (int, float)): + return Vector2D(round(self.abscissa - other, 5), round(self.ordinate - other, 5)) + return NotImplemented - # ваш код + def __rsub__(self, other): + if isinstance(other, Vector2D): + return Vector2D(round(self.abscissa - other.abscissa, 5), round(self.ordinate - other.ordinate, 5)) + + return NotImplemented + + def __neg__(self): + return Vector2D(-self.abscissa, -self.ordinate) + + def __float__(self) -> float: + return abs(self) + + def __int__(self) -> float: + return int(abs(self)) + + def __complex__(self) -> complex: + return complex(self.abscissa, self.ordinate) + + def __matmul__(self, other: 'Vector2D'): + if isinstance(other, Vector2D): + return (self.abscissa * other.abscissa + self.ordinate * other.ordinate) + return NotImplemented diff --git a/solutions/sem01/lesson12/task1.py b/solutions/sem01/lesson12/task1.py index d1bb828c1..bba337579 100644 --- a/solutions/sem01/lesson12/task1.py +++ b/solutions/sem01/lesson12/task1.py @@ -1,6 +1,19 @@ + from typing import Any, Generator, Iterable def chunked(iterable: Iterable, size: int) -> Generator[tuple[Any], None, None]: - # ваш код - ... + + iterator = iter(iterable) + + while True: + chunk = [] + try: + for i in range(size): + chunk.append(next(iterator)) + except StopIteration: + if chunk: + yield tuple(chunk) + break + + yield tuple(chunk) diff --git a/solutions/sem01/lesson12/task2.py b/solutions/sem01/lesson12/task2.py index 3ad802ee7..d9239b38f 100644 --- a/solutions/sem01/lesson12/task2.py +++ b/solutions/sem01/lesson12/task2.py @@ -2,5 +2,16 @@ def circle(iterable: Iterable) -> Generator[Any, None, None]: - # ваш код - ... + cache = [] + + for item in iterable: + cache.append(item) + yield item + + if not cache: + return + + index = 0 + while True: + yield cache[index] + index = (index + 1) % len(cache) \ No newline at end of file diff --git a/solutions/sem01/lesson12/task3.py b/solutions/sem01/lesson12/task3.py index 64c112ccc..108a54de3 100644 --- a/solutions/sem01/lesson12/task3.py +++ b/solutions/sem01/lesson12/task3.py @@ -6,7 +6,18 @@ def __init__( self, path_to_file: str, ) -> None: - # ваш код - ... + self.path_to_file = path_to_file + self.file = None + self.orig_stdout = None - # ваш код + def __enter__(self): + self.orig_stdout = sys.stdout + self.file = open(self.path_to_file, "w") + sys.stdout = self.file + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout = self.orig_stdout + if self.file: + self.file.close() + return False diff --git a/solutions/sem02/lesson03/task1.py b/solutions/sem02/lesson03/task1.py index 2c3fc0b58..99b5315f5 100644 --- a/solutions/sem02/lesson03/task1.py +++ b/solutions/sem02/lesson03/task1.py @@ -5,16 +5,17 @@ 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 lhs.shape != rhs.shape: + raise ShapeMismatchError + return 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 + return (np.sum((lhs[:, np.newaxis, :] - rhs[np.newaxis, :, :]) ** 2, axis=2)) ** 0.5 diff --git a/solutions/sem02/lesson03/task2.py b/solutions/sem02/lesson03/task2.py index fc823c1d6..9a24823e1 100644 --- a/solutions/sem02/lesson03/task2.py +++ b/solutions/sem02/lesson03/task2.py @@ -6,14 +6,24 @@ class ShapeMismatchError(Exception): def convert_from_sphere( - distances: np.ndarray, - azimuth: np.ndarray, - inclination: np.ndarray, -) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ... + distances: np.ndarray, azimuth: np.ndarray, inclination: np.ndarray,) -> tuple[np.ndarray, np.ndarray, np.ndarray]: + if not (distances.shape == azimuth.shape == inclination.shape): + raise ShapeMismatchError + + return tuple(( + distances * np.sin(inclination) * np.cos(azimuth), + distances * np.sin(inclination) * np.sin(azimuth), + distances * np.cos(inclination), + )) -def convert_to_sphere( - abscissa: np.ndarray, - ordinates: np.ndarray, - applicates: np.ndarray, -) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ... +def convert_to_sphere(abscissa: np.ndarray, ordinates: np.ndarray, applicates: np.ndarray, +) -> tuple[np.ndarray, np.ndarray, np.ndarray]: + if not (abscissa.shape == ordinates.shape == applicates.shape): + raise ShapeMismatchError + + distances = (abscissa ** 2 + ordinates ** 2 + applicates ** 2) ** 0.5 + azimuth = np.arctan2(ordinates, abscissa) + inclination = np.arccos(applicates / distances) + + return tuple(distances, azimuth, inclination) \ No newline at end of file diff --git a/solutions/sem02/lesson03/task3.py b/solutions/sem02/lesson03/task3.py index 477acd0ce..7e0824fbf 100644 --- a/solutions/sem02/lesson03/task3.py +++ b/solutions/sem02/lesson03/task3.py @@ -1,6 +1,13 @@ import numpy as np -def get_extremum_indices( - ordinates: np.ndarray, -) -> tuple[np.ndarray, np.ndarray]: ... +def get_extremum_indices(ordinates: np.ndarray,) -> tuple[np.ndarray, np.ndarray]: + if ordinates.size < 3: + raise ValueError + maximum = (ordinates[1:-1] > ordinates[:-2]) & (ordinates[1:-1] > ordinates[2:]) + minimum = (ordinates[1:-1] < ordinates[:-2]) & (ordinates[1:-1] < ordinates[2:]) + + maxima_inds = np.where(maximum)[0] + 1 + minima_inds = np.where(minimum)[0] + 1 + + return (minima_inds, maxima_inds) \ No newline at end of file diff --git a/solutions/sem02/lesson04/task1.py b/solutions/sem02/lesson04/task1.py index 1b5526c1f..bb0b80fb0 100644 --- a/solutions/sem02/lesson04/task1.py +++ b/solutions/sem02/lesson04/task1.py @@ -2,16 +2,53 @@ def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray: - # ваш код - return image + if pad_size < 1: + raise ValueError + + if len(image.shape) == 2: + length, width = image.shape[0], image.shape[1] + new_image = np.zeros((length + pad_size*2, width + pad_size*2), dtype=image.dtype) + new_image[pad_size:pad_size + length, pad_size:pad_size + width] = image + else: + length, width, color = image.shape[0], image.shape[1], image.shape[2] + new_image = np.zeros((length + pad_size*2, width + pad_size*2, color), dtype=image.dtype) + new_image[pad_size:pad_size + length, pad_size:pad_size + width, :] = image -def blur_image( - image: np.ndarray, - kernel_size: int, -) -> np.ndarray: - # ваш код - return image + return new_image + + + + + + +def blur_image(image: np.ndarray, kernel_size: int,) -> np.ndarray: + if kernel_size < 1 or kernel_size % 2 == 0: + raise ValueError + + if len(image.shape) == 2: + pad_size = kernel_size // 2 + new_image = pad_image(image, pad_size) + length, width = image.shape[0], image.shape[1] + result = np.zeros((length, width), dtype=np.uint8) + + for i in range(length): + for j in range(width): + window = new_image[i:i + kernel_size, j:j + kernel_size] + result[i, j] = np.mean(window) + + else: + pad_size = kernel_size // 2 + new_image = pad_image(image, pad_size) + length, width, color = image.shape[0], image.shape[1], image.shape[2] + result = np.zeros((length, width, color), dtype=np.uint8) + + for i in range(length): + for j in range(width): + window = new_image[i:i + kernel_size, j:j + kernel_size, :] + result[i, j, :] = np.mean(window) + + return result if __name__ == "__main__": diff --git a/solutions/sem02/lesson04/task2.py b/solutions/sem02/lesson04/task2.py index be9a2288f..2b0e3a06b 100644 --- a/solutions/sem02/lesson04/task2.py +++ b/solutions/sem02/lesson04/task2.py @@ -5,6 +5,32 @@ 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 + counts = np.zeros(256, dtype=np.int64) + for pixel in image.ravel(): + counts[pixel] += 1 + + max_pixels = 0 + best_color = 0 + + for current_color in range(256): + if counts[current_color] > 0: + left = max(0, current_color - (threshold - 1)) + right = min(255, current_color + (threshold - 1)) + cur_sum = np.sum(counts[left:right + 1]) + + if cur_sum > max_pixels: + max_pixels = cur_sum + best_color = current_color + + elif cur_sum == max_pixels: + if counts[current_color] > counts[best_color]: + best_color = current_color + + total_pixels = image.size + percent = (max_pixels / total_pixels) * 100 + + return np.uint8(best_color), float(percent) diff --git a/solutions/sem02/lesson05/task1.py b/solutions/sem02/lesson05/task1.py index e9c7c3c56..16cd6c3fa 100644 --- a/solutions/sem02/lesson05/task1.py +++ b/solutions/sem02/lesson05/task1.py @@ -5,8 +5,13 @@ class ShapeMismatchError(Exception): pass -def can_satisfy_demand( - costs: np.ndarray, - resource_amounts: np.ndarray, - demand_expected: np.ndarray, -) -> bool: ... +def can_satisfy_demand(costs: np.ndarray,resource_amounts: np.ndarray,demand_expected: np.ndarray,) -> bool: + if costs.shape[0] != len(resource_amounts) or costs.shape[1] != len(demand_expected): + raise ShapeMismatchError + + required_resources = costs @ demand_expected + for i in range(len(required_resources)): + if required_resources[i] > resource_amounts[i]: + return False + return True + \ No newline at end of file diff --git a/solutions/sem02/lesson05/task2.py b/solutions/sem02/lesson05/task2.py index be1fb9d2b..4d21245de 100644 --- a/solutions/sem02/lesson05/task2.py +++ b/solutions/sem02/lesson05/task2.py @@ -6,6 +6,17 @@ class ShapeMismatchError(Exception): def get_projections_components( - matrix: np.ndarray, - vector: np.ndarray, -) -> tuple[np.ndarray | None, np.ndarray | None]: ... + matrix: np.ndarray,vector: np.ndarray,) -> tuple[np.ndarray | None, np.ndarray | None]: + mshape = matrix.shape + if not (mshape[0] == mshape[1] and mshape[0] == vector.size): + raise ShapeMismatchError + + det = np.linalg.det(matrix) + if abs(det) < 1e-10: + return (None, None) + + ort_proj, ort_cond = [], [] + for base in matrix: + ort_proj.append((base @ vector) * base / (np.linalg.norm(base) ** 2)) + ort_cond.append(vector - (base @ vector) * base / (np.linalg.norm(base) ** 2)) + return (np.array(ort_proj), np.array(ort_cond)) \ No newline at end of file diff --git a/solutions/sem02/lesson05/task3.py b/solutions/sem02/lesson05/task3.py index 0c66906cb..a60b1f2ed 100644 --- a/solutions/sem02/lesson05/task3.py +++ b/solutions/sem02/lesson05/task3.py @@ -5,8 +5,12 @@ class ShapeMismatchError(Exception): pass -def adaptive_filter( - Vs: np.ndarray, - Vj: np.ndarray, - diag_A: np.ndarray, -) -> np.ndarray: ... +def adaptive_filter(Vs: np.ndarray, Vj: np.ndarray, diag_A: np.ndarray) -> np.ndarray: + if not (Vs.shape[0] == Vj.shape[0] and Vj.shape[1] == diag_A.shape[0]): + raise ShapeMismatchError + + Vj_H = np.transpose(np.conj(Vj)) + A = np.diag(diag_A) + I_K = np.eye(diag_A.size) + + return Vs - (Vj @ np.linalg.inv(I_K + Vj_H @ Vj @ A) @ (Vj_H @ Vs)) diff --git a/solutions/sem02/lesson07/data/result.png b/solutions/sem02/lesson07/data/result.png new file mode 100644 index 000000000..363e14cba Binary files /dev/null and b/solutions/sem02/lesson07/data/result.png differ diff --git a/solutions/sem02/lesson07/task1.py b/solutions/sem02/lesson07/task1.py index 3a505d89b..36941d0e2 100644 --- a/solutions/sem02/lesson07/task1.py +++ b/solutions/sem02/lesson07/task1.py @@ -13,8 +13,77 @@ def visualize_diagrams( ordinates: np.ndarray, diagram_type: Any, ) -> None: - # ваш код - pass + if abscissa.shape[0] != ordinates.shape[0]: + raise ShapeMismatchError + + if diagram_type not in ["hist", "box", "violin"]: + raise ValueError + + figure = plt.figure(figsize=(8, 8)) + grid = plt.GridSpec(4, 4, wspace=space, hspace=space) + + axis_scatter = figure.add_subplot(grid[0:-1, 1:]) + axis_hist_vert = figure.add_subplot(grid[0:-1, 0], sharey=axis_scatter) + axis_hist_hor = figure.add_subplot(grid[-1, 1:], sharex=axis_scatter) + + axis_scatter.scatter(abscissa, ordinates, color="cornflowerblue", alpha=0.5) + + if diagram_type == "box": + axis_hist_vert.boxplot( + ordinates, + patch_artist=True, + boxprops={"facecolor": "lightsteelblue"}, + medianprops={"color": "black"}, + ) + axis_hist_hor.boxplot( + abscissa, + vert=False, + patch_artist=True, + boxprops={"facecolor": "lightsteelblue"}, + medianprops={"color": "black"}, + ) + + elif diagram_type == "hist": + axis_hist_vert.hist( + ordinates, + orientation="horizontal", + bins=50, + color="cornflowerblue", + alpha=0.5, + density=True, + ) + axis_hist_hor.hist( + abscissa, + bins=50, + color="cornflowerblue", + alpha=0.5, + density=True, + ) + axis_hist_vert.invert_xaxis() + axis_hist_hor.invert_yaxis() + + elif diagram_type == "violin": + viol_vert = axis_hist_vert.violinplot(ordinates, showmedians=True) + for body in viol_vert["bodies"]: + body.set_facecolor("cornflowerblue") + body.set_edgecolor("blue") + for part in viol_vert: + if part != "bodies": + viol_vert[part].set_edgecolor("cornflowerblue") + + viol_hor = axis_hist_hor.violinplot(abscissa, vert=False, showmedians=True) + for body in viol_hor["bodies"]: + body.set_facecolor("cornflowerblue") + body.set_edgecolor("blue") + for part in viol_hor: + if part != "bodies": + viol_hor[part].set_edgecolor("cornflowerblue") + + axis_hist_hor.set_yticks([]) + axis_hist_vert.set_xticks([]) + + plt.show() + if __name__ == "__main__": @@ -24,5 +93,5 @@ def visualize_diagrams( abscissa, ordinates = np.random.multivariate_normal(mean, cov, size=1000).T - visualize_diagrams(abscissa, ordinates, "hist") + visualize_diagrams(abscissa, ordinates, "box") plt.show() diff --git a/solutions/sem02/lesson07/task2.py b/solutions/sem02/lesson07/task2.py index decd607ef..d8b8c8a0b 100644 --- a/solutions/sem02/lesson07/task2.py +++ b/solutions/sem02/lesson07/task2.py @@ -1 +1,42 @@ -# ваш код (используйте функции или классы для решения данной задачи) +import json +from pathlib import Path + +import matplotlib.pyplot as plt +import numpy as np + + +def get_counts(tier_list, stages_list): + arr = np.array(tier_list) + return np.array([np.sum(arr == stage) for stage in stages_list]) + + +def heart_task(): + plt.style.use("ggplot") + + with open("solutions\sem02\lesson07\data\medic_data.json") as file: + data = json.load(file) + + stages_list = ["I", "II", "III", "IV"] + before_count = get_counts(data["before"], stages_list) + after_count = get_counts(data["after"], stages_list) + + fig, ax = plt.subplots(figsize=(10, 7)) + x = np.arange(len(stages_list)) + width = 0.25 + + ax.bar(x - width / 2, before_count, width, label="before", color="lightcoral", edgecolor="darkred") + ax.bar(x + width / 2, after_count, width, label="after", color="cornflowerblue", edgecolor="darkblue") + + ax.set_title("Стадии митральной недостаточности") + ax.set_ylabel("Количество больных") + ax.set_xticks(x) + ax.set_xticklabels(stages_list) + ax.legend() + fig.tight_layout() + + plt.savefig("solutions/sem02/lesson07/data/result.png") + plt.show() + + +if __name__ == "__main__": + heart_task() \ No newline at end of file diff --git a/solutions/sem02/lesson08/task1.py b/solutions/sem02/lesson08/task1.py index 89f88572f..202d095b2 100644 --- a/solutions/sem02/lesson08/task1.py +++ b/solutions/sem02/lesson08/task1.py @@ -7,17 +7,48 @@ from matplotlib.animation import FuncAnimation -def create_modulation_animation( - modulation, - fc, - num_frames, - plot_duration, - time_step=0.001, - animation_step=0.01, - save_path="" -) -> FuncAnimation: - # ваш код - return FuncAnimation() +def create_modulation_animation(modulation, fc, num_frames, plot_duration, time_step=0.001, animation_step=0.01,save_path="") -> FuncAnimation: + def signal(t, modulation, fc): + base_signal = np.sin(2 * np.pi * fc * t) + if modulation is None: + return base_signal + return modulation(t) * base_signal + + figure, axis = plt.subplots(figsize=(12, 6)) + num_points = int(plot_duration / time_step) + 1 + time_segment = np.linspace(0, plot_duration, num_points) + num_segment = signal(time_segment, modulation, fc) + line, *_ = axis.plot(time_segment, num_segment, c="crimson") + result_duration = (num_frames - 1) * animation_step + plot_duration + result_num_points = int(result_duration / time_step) + 1 + result_time = np.linspace(0, result_duration, result_num_points) + total_signal = signal(result_time, modulation, fc) + axis.set_xlim(0, plot_duration) + ymax = 1.2 * np.max(np.abs(total_signal)) + axis.set_ylim(-ymax, ymax) + + def update(frame_id): + start = frame_id * animation_step + end = start + plot_duration + start_index = int(start / time_step) + end_index = start_index + num_points + time_minisegment = result_time[start_index:end_index] + signal_minisegment = total_signal[start_index:end_index] + line.set_data(time_minisegment, signal_minisegment) + axis.set_xlim(start, end) + return (line,) + + animation = FuncAnimation( + figure, + update, + frames=num_frames, + interval=50, + blit=False, + ) + if save_path: + animation.save(save_path, writer="pillow", fps=24) + return animation + if __name__ == "__main__": diff --git a/tempCodeRunnerFile.python b/tempCodeRunnerFile.python new file mode 100644 index 000000000..51cf89807 --- /dev/null +++ b/tempCodeRunnerFile.python @@ -0,0 +1 @@ +print("asd") \ No newline at end of file