The minimum sum is
402 produced by the following pairs of subsets:
(4, 6, 8) and (1, 2, 3, 5, 7)
(5, 6, 7) and (1, 2, 3, 4, 8)
(1, 4, 6, 8) and (2, 3, 5, 7)
(1, 5, 6, 7) and (2, 3, 4, 8)
----------
Output:
The minimum sum of Pa and Pb is 402
(4, 6, 8)
(5, 6, 7)
(1, 4, 6, 8)
(1, 5, 6, 7)
(2, 3, 4, 8)
(2, 3, 5, 7)
(1, 2, 3, 4, 8)
(1, 2, 3, 5, 7)
"""
x = [i for i in range(1,9)]
from itertools import combinations
minsum = 10000000000000
mincomb = ()
for a in range(1,8):
for comb in combinations(x,a):
pa = 1
pb = 1
for i in range(1,9):
if i in comb:
pa *= i
else:
pb *= i
pab_sum = pa+pb
if pab_sum < minsum:
minsum = pab_sum
mincomb = comb
print('The minimum sum of Pa and Pb is', minsum)
for a in range(1,8):
for comb in combinations(x,a):
pa = 1
pb = 1
for i in range(1,9):
if i in comb:
pa *= i
else:
pb *= i
pab_sum = pa+pb
if pab_sum == minsum:
print(comb)
|
Posted by Larry
on 2023-06-20 13:55:12 |