Cody

Solution 930230

Submitted on 31 Jul 2016 by Martin C.
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))

b = [] mindistance = 1 minpos = 1 b = 1 a = 2 3 4 mindistance = 2 minpos = 1 b = 1 2 a = 3 4 mindistance = 3 minpos = 1 b = 1 2 3 a = 4 mindistance = 4 minpos = 1 b = 1 2 3 4 a = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 s = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 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))

b = [] mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 mindistance = 1.6000 minpos = 7 mindistance = 0.6000 minpos = 8 mindistance = 0.4000 minpos = 9 b = 4 a = -4 -3 -2 -1 0 1 2 3 5 6 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 mindistance = 1.6000 minpos = 7 mindistance = 0.6000 minpos = 8 b = 4 3 a = -4 -3 -2 -1 0 1 2 5 6 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 mindistance = 1.6000 minpos = 7 mindistance = 1.4000 minpos = 8 b = 4 3 5 a = -4 -3 -2 -1 0 1 2 6 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 mindistance = 1.6000 minpos = 7 b = 4 3 5 2 a = -4 -3 -2 -1 0 1 6 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 mindistance = 2.4000 minpos = 7 b = 4 3 5 2 6 a = -4 -3 -2 -1 0 1 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 2.6000 minpos = 6 b = 4 3 5 2 6 1 a = -4 -3 -2 -1 0 7 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 mindistance = 3.4000 minpos = 6 b = 4 3 5 2 6 1 7 a = -4 -3 -2 -1 0 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 3.6000 minpos = 5 b = 4 3 5 2 6 1 7 0 a = -4 -3 -2 -1 8 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 mindistance = 4.4000 minpos = 5 b = 4 3 5 2 6 1 7 0 8 a = -4 -3 -2 -1 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 4.6000 minpos = 4 b = 4 3 5 2 6 1 7 0 8 -1 a = -4 -3 -2 9 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 mindistance = 5.4000 minpos = 4 b = 4 3 5 2 6 1 7 0 8 -1 9 a = -4 -3 -2 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 5.6000 minpos = 3 b = 4 3 5 2 6 1 7 0 8 -1 9 -2 a = -4 -3 10 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 mindistance = 6.4000 minpos = 3 b = 4 3 5 2 6 1 7 0 8 -1 9 -2 10 a = -4 -3 mindistance = 7.6000 minpos = 1 mindistance = 6.6000 minpos = 2 b = 4 3 5 2 6 1 7 0 8 -1 9 -2 10 -3 a = -4 mindistance = 7.6000 minpos = 1 b = 4 3 5 2 6 1 7 0 8 -1 9 -2 10 -3 -4 a = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 s = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 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))

b = [] mindistance = 8.8584 minpos = 1 b = 12 a = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 s = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 b = 12

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

b = [] mindistance = 200 minpos = 1 mindistance = 199 minpos = 2 mindistance = 198 minpos = 3 mindistance = 197 minpos = 4 mindistance = 196 minpos = 5 mindistance = 195 minpos = 6 b = -95 a = -100 -99 -98 -97 -96 mindistance = 200 minpos = 1 mindistance = 199 minpos = 2 mindistance = 198 minpos = 3 mindistance = 197 minpos = 4 mindistance = 196 minpos = 5 b = -95 -96 a = -100 -99 -98 -97 mindistance = 200 minpos = 1 mindistance = 199 minpos = 2 mindistance = 198 minpos = 3 mindistance = 197 minpos = 4 b = -95 -96 -97 a = -100 -99 -98 mindistance = 200 minpos = 1 mindistance = 199 minpos = 2 mindistance = 198 minpos = 3 b = -95 -96 -97 -98 a = -100 -99 mindistance = 200 minpos = 1 mindistance = 199 minpos = 2 b = -95 -96 -97 -98 -99 a = -100 mindistance = 200 minpos = 1 b = -95 -96 -97 -98 -99 -100 a = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 s = Empty matrix: 1-by-0 d = Empty matrix: 1-by-0 b = -100 -99 -98 -97 -96 -95

Suggested Problems

More from this Author95