combinations 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: combinations
3
+ Version: 1.0
4
+ Summary: Helps to find combinations
5
+ Author-email: maximsavaldin@gmail.com
6
+ Dynamic: author-email
7
+ Dynamic: summary
@@ -0,0 +1 @@
1
+ from main import find_combinations
@@ -0,0 +1,41 @@
1
+ def find_combinations(numbers, target):
2
+ results = []
3
+ # Сортируем для оптимизации и исключения дубликатов
4
+ numbers.sort()
5
+
6
+ def backtrack(start, current_sum, path):
7
+ # Если нашли нужную сумму, сохраняем копию пути
8
+ if current_sum == target:
9
+ results.append(list(path))
10
+ return
11
+ # Если перешагнули лимит, останавливаем ветку
12
+ if current_sum > target:
13
+ return
14
+
15
+ for i in range(start, len(numbers)):
16
+ # Пропускаем одинаковые числа на одном уровне рекурсии, чтобы избежать дубликатов в ответе
17
+ if i > start and numbers[i] == numbers[i - 1]:
18
+ continue
19
+
20
+ # Шаг вперед
21
+ path.append(numbers[i])
22
+ # Рекурсивный запуск со следующего элемента
23
+ backtrack(i + 1, current_sum + numbers[i], path)
24
+ # Откат назад (backtrack)
25
+ path.pop()
26
+
27
+ backtrack(0, 0, [])
28
+ return results
29
+
30
+
31
+ # --- Пример использования ---
32
+ my_numbers = [10, 1, 2, 7, 6, 1, 5]
33
+ target_sum = 8
34
+
35
+ combinations = find_combinations(my_numbers, target_sum)
36
+
37
+ print(f"Исходный список: {my_numbers}")
38
+ print(f"Искомая сумма: {target_sum}")
39
+ print("Найденные комбинации:")
40
+ for combo in combinations:
41
+ print(combo)
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: combinations
3
+ Version: 1.0
4
+ Summary: Helps to find combinations
5
+ Author-email: maximsavaldin@gmail.com
6
+ Dynamic: author-email
7
+ Dynamic: summary
@@ -0,0 +1,9 @@
1
+ setup.cfg
2
+ setup.py
3
+ combinations/__init__.py
4
+ combinations/main.py
5
+ combinations.egg-info/PKG-INFO
6
+ combinations.egg-info/SOURCES.txt
7
+ combinations.egg-info/dependency_links.txt
8
+ combinations.egg-info/not-zip-safe
9
+ combinations.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ combinations
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ from setuptools import setup
2
+
3
+ setup(name='combinations',
4
+ version='1.0',
5
+ description='Helps to find combinations',
6
+ packages=['combinations'],
7
+ author_email='maximsavaldin@gmail.com',
8
+ zip_safe=False)