From cb801cc8a7f9fb4f58e64aeb182635b37b44cc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D1=88=D0=BC=D0=B0=D0=BD=20=D0=90=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=20=D0=9B=D0=B5=D0=B9=D0=B1=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Mon, 27 Jul 2026 15:27:30 +0300 Subject: [PATCH] Initial code version --- pyproject.toml | 0 src/urbrato_algo/__init__.py | 2 ++ src/urbrato_algo/lazy_graphs.py | 42 +++++++++++++++++++++++++++++++++ tests/lazy_graphs_test.py | 6 +++++ 4 files changed, 50 insertions(+) create mode 100644 pyproject.toml create mode 100644 src/urbrato_algo/__init__.py create mode 100644 src/urbrato_algo/lazy_graphs.py create mode 100644 tests/lazy_graphs_test.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/urbrato_algo/__init__.py b/src/urbrato_algo/__init__.py new file mode 100644 index 0000000..3c507d5 --- /dev/null +++ b/src/urbrato_algo/__init__.py @@ -0,0 +1,2 @@ +__version__ = '1.0.0' +__author__ = 'Urbrato' \ No newline at end of file diff --git a/src/urbrato_algo/lazy_graphs.py b/src/urbrato_algo/lazy_graphs.py new file mode 100644 index 0000000..1c8a8ef --- /dev/null +++ b/src/urbrato_algo/lazy_graphs.py @@ -0,0 +1,42 @@ +from collections import deque +from collections.abc import Callable, Hashable, Iterable + + +def find_chain[T: Hashable]( + objects: Iterable[T], + start: T, + end: T, + is_next: Callable[[T, T], bool] +) -> list[T]: + nodes = list(objects) + + if start == end: + return [start] + + visited: set[T] = {start} + parent: dict[T, T | None] = {start: None} + queue = deque([start]) + + while queue: + current = queue.popleft() + + for node in nodes: + if node not in visited and is_next(current, node): + visited.add(node) + parent[node] = current + queue.append(node) + + if node == end: + queue.clear() + break + + if end not in parent: + return [] + + path: list[T] = [] + curr: T | None = end + while curr is not None: + path.append(curr) + curr = parent[curr] + + return path[::-1] diff --git a/tests/lazy_graphs_test.py b/tests/lazy_graphs_test.py new file mode 100644 index 0000000..1231200 --- /dev/null +++ b/tests/lazy_graphs_test.py @@ -0,0 +1,6 @@ +#import urbrato_algo.lazy_graphs as graphs + +#words = ['вино', 'сука', 'срок', 'арка', 'тура', 'сова', 'жара', 'день', 'жгут', 'урна', 'заяц', 'зона', 'звук', 'гора', 'гусь', 'руна', 'суша', 'тара', 'враг', 'арба', 'кара', 'поза', 'бобр', 'икра', 'слон', 'доза', 'знак', 'груз', 'глаз', 'жаба', 'база', 'дока', 'губа', 'блин', 'жена', 'доля', 'роса', 'бита', 'каюк', 'друг', 'вера', 'заря', 'дыра', 'буря', 'дача', 'вода', 'кафр', 'дума', 'драп', 'баян', 'суха', 'диво', 'грач', 'дочь', 'брат', 'дуга', 'каюр', 'крюк', 'звон', 'пола', 'вата', 'град', 'банк', 'рука', 'сока', 'урюк', 'иней', 'дека', 'борт', 'бокс', 'сухо', 'мура', 'балл', 'врач', 'долг', 'урок', 'стон', 'мука', 'азот', 'лука', 'кафе', 'жест', 'вход', 'волк', 'муха', 'блок', 'гриф', 'жбан', 'двор', 'дело', 'зима', 'ваза', 'рана', 'сток', 'змея', 'каре', 'горе', 'полк', 'роза', 'арфа', 'игра'] + +# здесь продолжайте программу +#print(graphs.find_chain(words, 'мура', 'сухо', lambda a,b: sum(1 for i in range(len(a)) if a[i] != b[i]) == 1)) \ No newline at end of file