algorithm - How to find the largest sum and smallest positive difference? -
using numbers 9, 8, 7, 6, 5, , 4 once each, find following:
a) largest possible sum
is there more on solution gives largest possible sum? how know it's largest possible sum?
b) smallest possible (positive) difference
is there more 1 solution? how know it's smallest possible difference?
the numbers must 3 digits. example, 965 + 784 or 879 - 654
hmm interesting
difference:
if take tupels (a_1,b_1),(a_2,b_2),(a_3,b_3) a_1a_2a_3-b_1b_2b_3, difference is:
100*(a_1-b_1)+10*(a_2-b_2)+(a_1-b_1) so smallest difference guess should fullfilled: -(a_2-b_2) > -(a_3-b_3) > (a_1-b_1):
(a_2-b_2) = 4-9 = -5 = d_2 (a_3-b_3) = 5-8 = -3 = d_3 (a_1-b_1) = 7-6 = 1 = d_1 giving 745-698 = 47 smallest because in other variants d_2 bigger or d_3 bigger or d_1. unique (so 1 solution) because it's asked after positive difference, cannot switch numbers.
sum:
so sum got:
100*(a_1+b_1) + 10*(a_2+b_2) + (a_2+b_2) so now: (a_1+b_1)>(a_2+b_2)>(a_3+b_3):
a_1+b_1 = 8+9 = 17 a_2+b_2 = 7+6 = 13 a_3+b_3 = 4+5 = 9 so it's 964+875 = 975+864 = 1839, it's not unique, still biggest. can change b_i , a_i have 2^3 possiblities build sum.
Comments
Post a Comment