Cody

Problem 94. Target sorting

Solution 1901123

Submitted on 15 Aug 2019 by Tetsuji Tsuda
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))

var = 1 2 3 4 var = 1 2 3 4 diff = 1 2 3 4 diff = 1 2 3 4 T = 4×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>____</strong> 1 1 2 2 3 3 4 4 T = 4×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>____</strong> 4 4 3 3 2 2 1 1 b = 4 3 2 1 b = 4 3 2 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))

var = -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 var = -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 diff = 7.6000 6.6000 5.6000 4.6000 3.6000 2.6000 1.6000 0.6000 0.4000 1.4000 2.4000 3.4000 4.4000 5.4000 6.4000 diff = 7.6000 6.6000 5.6000 4.6000 3.6000 2.6000 1.6000 0.6000 0.4000 1.4000 2.4000 3.4000 4.4000 5.4000 6.4000 T = 15×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>____</strong> -4 7.6 -3 6.6 -2 5.6 -1 4.6 0 3.6 1 2.6 2 1.6 3 0.6 4 0.4 5 1.4 6 2.4 7 3.4 8 4.4 9 5.4 10 6.4 T = 15×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>____</strong> -4 7.6 -3 6.6 10 6.4 -2 5.6 9 5.4 -1 4.6 8 4.4 0 3.6 7 3.4 1 2.6 6 2.4 2 1.6 5 1.4 3 0.6 4 0.4 b = -4 -3 10 -2 9 -1 8 0 7 1 6 2 5 3 4 b = -4 -3 10 -2 9 -1 8 0 7 1 6 2 5 3 4

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

var = 12 var = 12 diff = 8.8584 diff = 8.8584 T = 1×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>______</strong> 12 8.8584 T = 1×2 table <strong>var</strong> <strong>diff</strong> <strong>___</strong> <strong>______</strong> 12 8.8584 b = 12 b = 12

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

var = -100 -99 -98 -97 -96 -95 var = -100 -99 -98 -97 -96 -95 diff = 200 199 198 197 196 195 diff = 200 199 198 197 196 195 T = 6×2 table <strong>var</strong> <strong>diff</strong> <strong>____</strong> <strong>____</strong> -100 200 -99 199 -98 198 -97 197 -96 196 -95 195 T = 6×2 table <strong>var</strong> <strong>diff</strong> <strong>____</strong> <strong>____</strong> -100 200 -99 199 -98 198 -97 197 -96 196 -95 195 b = -100 -99 -98 -97 -96 -95 b = -100 -99 -98 -97 -96 -95