37 lines
946 B
Python
37 lines
946 B
Python
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)
|