Cody

# Problem 42383. Combined Ages 3 - Non-symmetric, n ≥ 3

Solution 3032755

Submitted on 2 Oct 2020 by Augusto Mazzei
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
ABCD = 70; ABC = 65; AB = 40; BC = 52; y = combined_ages_nonsymmetric(ABCD,ABC,AB,BC); y_correct = [13;27;25;5]; for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 13 27 25 5

2   Pass
ABC = 70; BC = 50; AC = 40; y = combined_ages_nonsymmetric(ABC,BC,AC); y_correct = [20;30;20]; for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 age = 20 30 20

3   Pass
ABCD = 100; ABC = 80; BCD = 70; ABD = 60; y = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD); y_correct = [30;10;40;20]; for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 30 10 40 20

4   Pass
AB = 34; BC = 54; ABC = 86; y = combined_ages_nonsymmetric(AB,BC,ABC); y_correct = [32;2;52]; for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 age = 32 2 52

5   Pass
ABCDE = 120; ABCD = 78; ABC = 45; AB = 24; AC = 31; y = combined_ages_nonsymmetric(ABCDE,ABCD,ABC,AB,AC); y_correct = [10,14,21,33,42]; for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 10 14 21 33 42

6   Pass
y_correct = [37 33 31 38]; ABC = y_correct(1) + y_correct(2) + y_correct(3); BCD = y_correct(2) + y_correct(3) + y_correct(4); ACD = y_correct(1) + y_correct(3) + y_correct(4); ABD = y_correct(1) + y_correct(2) + y_correct(4); y = combined_ages_nonsymmetric(ABC,BCD,ACD,ABD); for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 37 33 31 38

7   Pass
y_correct = [5 15 30 62 100]; AB = y_correct(1) + y_correct(2); BC = y_correct(2) + y_correct(3); AC = y_correct(1) + y_correct(3); ACE = y_correct(1) + y_correct(3) + y_correct(5); ABDE = y_correct(1) + y_correct(2) + y_correct(4) + y_correct(5); y = combined_ages_nonsymmetric(AB,BC,AC,ACE,ABDE); for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 5 15 30 62 100

8   Pass
y_correct = [2 3 5 7 11 17 23 31 42 55]; AB = y_correct(1) + y_correct(2); BC = y_correct(2) + y_correct(3); AC = y_correct(1) + y_correct(3); ABCD = y_correct(1) + y_correct(2) + y_correct(3) + y_correct(4); CDEG = y_correct(3) + y_correct(4) + y_correct(5) + y_correct(7); BFH = y_correct(2) + y_correct(6) + y_correct(8); FGIJ = y_correct(6) + y_correct(7) + y_correct(9) + y_correct(10); ACEGH = y_correct(1) + y_correct(3) + y_correct(5) + y_correct(7) + y_correct(8); BEJ = y_correct(2) + y_correct(5) + y_correct(10); ABDIJ = y_correct(1) + y_correct(2) + y_correct(4) + y_correct(9) + y_correct(10); y = combined_ages_nonsymmetric(AB,BC,AC,ABCD,CDEG,BFH,FGIJ,ACEGH,BEJ,ABDIJ); for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 age = 2 3 5 7 11 17 23 31 42 55

9   Pass
ind = randi(4); switch ind case 1 ABCD = 70; ABC = 65; AB = 40; BC = 52; y = combined_ages_nonsymmetric(ABCD,ABC,AB,BC); y_correct = [13;27;25;5]; case 2 ABCD = 100; ABC = 80; BCD = 70; ABD = 60; y = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD); y_correct = [30;10;40;20]; case 3 AB = 34; BC = 54; ABC = 86; y = combined_ages_nonsymmetric(AB,BC,ABC); y_correct = [32;2;52]; case 4 ABC = 70; BC = 50; AC = 40; y = combined_ages_nonsymmetric(ABC,BC,AC); y_correct = [20;30;20]; end for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 age = 32 2 52

10   Pass
ind = randi(4); switch ind case 1 ABC = 70; BC = 50; AC = 40; y = combined_ages_nonsymmetric(ABC,BC,AC); y_correct = [20;30;20]; case 2 AB = 34; BC = 54; ABC = 86; y = combined_ages_nonsymmetric(AB,BC,ABC); y_correct = [32;2;52]; case 3 ABCD = 70; ABC = 65; AB = 40; BC = 52; y = combined_ages_nonsymmetric(ABCD,ABC,AB,BC); y_correct = [13;27;25;5]; case 4 ABCD = 100; ABC = 80; BCD = 70; ABD = 60; y = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD); y_correct = [30;10;40;20]; end for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 age = 32 2 52

11   Pass
ind = randi(4); switch ind case 1 AB = 34; BC = 54; ABC = 86; y = combined_ages_nonsymmetric(AB,BC,ABC); y_correct = [32;2;52]; case 2 ABCD = 100; ABC = 80; BCD = 70; ABD = 60; y = combined_ages_nonsymmetric(ABCD,ABC,BCD,ABD); y_correct = [30;10;40;20]; case 3 ABCD = 70; ABC = 65; AB = 40; BC = 52; y = combined_ages_nonsymmetric(ABCD,ABC,AB,BC); y_correct = [13;27;25;5]; case 4 ABC = 70; BC = 50; AC = 40; y = combined_ages_nonsymmetric(ABC,BC,AC); y_correct = [20;30;20]; end for i = 1:numel(y_correct) assert(isequal(y(i),y_correct(i))) end

A = 0 0 0 0 0 0 0 0 0 age = 20 30 20

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!