Cody

# Problem 1985. How unique?

Solution 403875

Submitted on 13 Feb 2014 by Simon
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 = [2 2 2 3 3 2 3 8 6 5 6]; [U, H] = hunique(A); U_ok = [2 3 8 6 5]; H_ok = [4 3 1 2 1]; assert(isequal(U,U_ok)); assert(isequal(H,H_ok));

u = 2 3 8 6 5 v = 2 3 5 6 8 i = 1 2 5 4 3 f = 4 3 1 2 1 w = 4 3 1 2 1

2   Pass
%% A = [2 2 2 3 3 2 3 8 6 5 6 8]; [U, H] = hunique(A); U_ok = [2 3 8 6 5]; H_ok = [4 3 2 2 1]; assert(isequal(U,U_ok)); assert(isequal(H,H_ok));

u = 2 3 8 6 5 v = 2 3 5 6 8 i = 1 2 5 4 3 f = 4 3 1 2 2 w = 4 3 2 2 1

3   Pass
%% A = 100:-11:1; assert(isequal(hunique(A),A)); [~,H] = hunique(A); assert(isequal(H,ones(1,10)));

u = 100 89 78 67 56 45 34 23 12 1 v = 1 12 23 34 45 56 67 78 89 100 i = 10 9 8 7 6 5 4 3 2 1 f = 1 1 1 1 1 1 1 1 1 1 w = 1 1 1 1 1 1 1 1 1 1 u = 100 89 78 67 56 45 34 23 12 1 v = 1 12 23 34 45 56 67 78 89 100 i = 10 9 8 7 6 5 4 3 2 1 f = 1 1 1 1 1 1 1 1 1 1 w = 1 1 1 1 1 1 1 1 1 1

4   Pass
%% A = randi([-10 10],1,100); [U,H] = hunique(A); assert(sum(H)==numel(A)); assert(isequal(unique(A),sort(U))); % number of test cases may increace in the future. % any proposals of test cases warmly welcome.

u = Columns 1 through 16 6 0 8 -3 -1 10 -10 -7 4 2 3 7 -9 -6 -2 -8 Columns 17 through 21 -5 -4 9 5 1 v = Columns 1 through 16 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 Columns 17 through 21 6 7 8 9 10 i = Columns 1 through 16 7 13 16 8 14 17 18 4 15 5 2 21 10 11 9 20 Columns 17 through 21 1 12 3 19 6 f = Columns 1 through 16 6 4 4 2 3 3 6 7 2 5 4 5 5 5 5 6 Columns 17 through 21 6 4 7 6 5 w = Columns 1 through 16 6 5 6 7 5 6 4 2 5 3 4 5 5 4 2 6 Columns 17 through 21 6 5 4 7 3

### Community Treasure Hunt

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

Start Hunting!