Cody

# Problem 44510. Besson Ranks

Solution 1431810

Submitted on 2 Feb 2018 by J-G van der Toorn
• Size: 21
• This is the leading solution.
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
x = [1 2]; y_correct = [1 2]; assert(isequal(bessonRanks(x),y_correct))

2   Pass
x = [1 1]; % (1 + 2)/2 = 1.5 y_correct = [1.5 1.5]; assert(isequal(bessonRanks(x),y_correct))

3   Pass
x = [1 1 1]; % (1 + 2 + 3)/3 = 2 y_correct = [2 2 2]; assert(isequal(bessonRanks(x),y_correct))

4   Pass
x = [1 1 1 1]; % (1 + 2 + 3 + 4)/4 = 2.5 y_correct = [2.5 2.5 2.5 2.5]; assert(isequal(bessonRanks(x),y_correct))

5   Pass
x = [1 1 1 1 1]; % (1 + 2 + 3 + 4 + 5)/5=3 y_correct = [3 3 3 3 3]; assert(isequal(bessonRanks(x),y_correct))

6   Pass
x = [1 2 2 3]; y_correct = [1 2.5 2.5 4]; assert(isequal(bessonRanks(x),y_correct))

7   Pass
x = [1 2 3 3]; y_correct = [1 2 3.5 3.5]; % 7/2 = 3.5 assert(isequal(bessonRanks(x),y_correct))

8   Pass
x = [1 1 2 3]; y_correct = [1.5 1.5 3 4]; % (1+2)/2 = 1.5 assert(isequal(bessonRanks(x),y_correct))

9   Pass
x = [1 1 2 2]; y_correct = [1.5 1.5 3.5 3.5]; % (1+2)/2 = 1.5 and (3+4)/2=3.5 assert(isequal(bessonRanks(x),y_correct))

10   Pass
x = [6.8 7.2 6.8 5.4 6.3]; y_correct = [3.5 5 3.5 1 2]; assert(isequal(bessonRanks(x),y_correct))

11   Pass
x = [6.8 7.2 6.8 5.4 6.3]; y_correct = [3.5 5 3.5 1 2]; assert(isequal(bessonRanks(x),y_correct))

12   Pass
x = [9 5 9 4 3 4 1 9 9 2 4 ]; y_correct = [9.5 7 9.5 5 3 5 1 9.5 9.5 2 5]; assert(isequal(bessonRanks(x),y_correct))

13   Pass
x = [2 2 2 3 3 3 4 4 4 ]; y_correct = [2 2 2 5 5 5 8 8 8 ]; assert(isequal(bessonRanks(x),y_correct))

14   Pass
x = [10 20 10 30 10 20 20 20 20 30]; y_correct = [2 6 2 9.5 2 6 6 6 6 9.5]; assert(isequal(bessonRanks(x),y_correct))

15   Pass
x = [2 5 1.7 4 5.5 5.5 1.7 2 5]; y_correct = [3.5 6.5 1.5 5 8.5 8.5 1.5 3.5 6.5]; assert(isequal(bessonRanks(x),y_correct))

16   Pass
for idx = 1:20 x = rand(1); y_correct = [1]; assert(isequal(bessonRanks(x),y_correct)) end

17   Pass
for idx = 1:30 k = randi([20 90]); n = randperm(k); [~, y_correct]= sort(n); end

18   Pass
x = [1 1 2 1 3 3 2]; y_correct = [2 2 4.5 2 6.5 6.5 4.5]; assert(isequal(bessonRanks(x),y_correct))

### Community Treasure Hunt

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

Start Hunting!