From 5087b2a30839588bccb705e444cc30d830f36f67 Mon Sep 17 00:00:00 2001 From: Andrey Golikov Date: Fri, 10 Apr 2026 19:53:47 +0600 Subject: [PATCH] feat: add task 7 naive approach --- task7/naive_approach.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 task7/naive_approach.py diff --git a/task7/naive_approach.py b/task7/naive_approach.py new file mode 100644 index 0000000..1fd62f2 --- /dev/null +++ b/task7/naive_approach.py @@ -0,0 +1,36 @@ +from itertools import repeat +import random +from typing import Final, Iterable + +from icecream import ic + + +sets_count: Final[int] = random.randint(2, 1000) +elements_count: Final[Iterable[int]] = (random.randint(3, 10000) for _ in repeat(None, sets_count)) + +ic(sets_count) + +sets: list[set[int]] = [ + set( + random.sample(range(-2_000_000_000, 2_000_000_000 + 1), count) + ) + for count in elements_count +] +sets.sort(key=lambda x: len(x), reverse=True) +ic(list(map(len, sets))) + +max_intersection = 0 + +for i in range(len(sets) - 1): + if max_intersection >= len(sets[i]): + ic(f"break on {i}") + break + for j in range(i + 1, len(sets)): + if max_intersection > len(sets[j]): + ic(f"break on {i};{j}") + break + if (intersection := len(sets[i].intersection(sets[j]))) > max_intersection: + max_intersection = intersection + ic(max_intersection) + +print(max_intersection)