A set contains four numbers. The six pairwise sums of distinct elements of the set, in no particular order, are 189, 320, 287, 264, x, and y. Find the greatest possible value of: x + y.
The required greatest possible sum of x+y is 761
Case 1:
a b c d x y
83 106 181 237 343 418
a+b a+c a+d b+c b+d c+d
189 264 320 287 343 418
and the sum is: 761
Case 2 yields no solutions.
Code follows:
# case 1
theSum = 0
for a in range (190):
b = 189 - a
c = 264 - a
d = 320 - a
if (b+c) != 287:
continue
x = b+d
y = c+d
theSum = x+y
print('Case 1: ')
print('a b c d x y')
print(a,b,c,d,x,y)
print('\n', 'a+b a+c a+d b+c b+d c+d')
print(a+b,a+c,a+d,b+c,b+d,c+d)
print('\n', 'and the sum is: ', theSum)
# case 2 provides no solutions
theSum = 0
for a in range (190):
b = 189 - a
c = 264 - a
d = 287 - a
if (b+c) != 320:
continue
x = b+d
y = c+d
theSum = x+y
print('Case 2: ')
print('a b c d x y')
print(a,b,c,d,x,y)
print('\n', 'a+b a+c a+d b+c b+d c+d')
print(a+b,a+c,a+d,b+c,b+d,c+d)
print('\n', 'and the sum is: ', theSum)
|
Posted by Larry
on 2020-11-30 09:58:19 |