Cody

Problem 94. Target sorting

Solution 1048227

Submitted on 8 Nov 2016 by SirSteve26
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
a = [1 2 3 4]; t = 0; b_correct = [4 3 2 1]; assert(isequal(targetSort(a,t),b_correct))

diff = 1 val = 1 diff = 2 val = 2 diff = 3 val = 3 diff = 4 val = 4 diff = 1 val = 1 diff = 2 val = 2 diff = 3 val = 3 diff = 1 val = 1 diff = 2 val = 2 diff = 1 val = 1

2   Pass
a = -4:10; t = 3.6; b_correct = [-4 -3 10 -2 9 -1 8 0 7 1 6 2 5 3 4]; assert(isequal(targetSort(a,t),b_correct))

diff = 7.6000 val = -4 diff = 6.6000 val = -3 diff = 5.6000 val = -2 diff = 6.4000 val = 10 diff = 5.6000 val = -2 diff = 4.6000 val = -1 diff = 5.4000 val = 9 diff = 4.6000 val = -1 diff = 3.6000 val = 0 diff = 4.4000 val = 8 diff = 3.6000 val = 0 diff = 2.6000 val = 1 diff = 3.4000 val = 7 diff = 2.6000 val = 1 diff = 1.6000 val = 2 diff = 2.4000 val = 6 diff = 1.6000 val = 2 diff = 0.6000 val = 3 diff = 1.4000 val = 5 diff = 0.6000 val = 3 diff = 0.4000 val = 4

3   Pass
a = 12; t = pi; b_correct = 12; assert(isequal(targetSort(a,t),b_correct))

diff = 8.8584 val = 12

4   Pass
a = -100:-95; t = 100; b_correct = [-100 -99 -98 -97 -96 -95]; assert(isequal(targetSort(a,t),b_correct))

diff = 200 val = -100 diff = 199 val = -99 diff = 198 val = -98 diff = 197 val = -97 diff = 196 val = -96 diff = 195 val = -95