Cody

Solution 1212843

Submitted on 15 Jun 2017 by Noriko Hounoki
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));

num = 5 U = 0 0 0 0 0 H = 0 0 0 0 0 k = 1×11 logical array 1 1 1 0 0 1 0 0 0 0 0 U = 2 0 0 0 0 H = 4 0 0 0 0 A = 3 3 3 8 6 5 6 k = 1×7 logical array 1 1 1 0 0 0 0 U = 2 3 0 0 0 H = 4 3 0 0 0 A = 8 6 5 6 k = 1×4 logical array 1 0 0 0 U = 2 3 8 0 0 H = 4 3 1 0 0 A = 6 5 6 k = 1×3 logical array 1 0 1 U = 2 3 8 6 0 H = 4 3 1 2 0 A = 5 k = logical 1 U = 2 3 8 6 5 H = 4 3 1 2 1 A = 1×0 empty double row vector

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));

num = 5 U = 0 0 0 0 0 H = 0 0 0 0 0 k = 1×12 logical array 1 1 1 0 0 1 0 0 0 0 0 0 U = 2 0 0 0 0 H = 4 0 0 0 0 A = 3 3 3 8 6 5 6 8 k = 1×8 logical array 1 1 1 0 0 0 0 0 U = 2 3 0 0 0 H = 4 3 0 0 0 A = 8 6 5 6 8 k = 1×5 logical array 1 0 0 0 1 U = 2 3 8 0 0 H = 4 3 2 0 0 A = 6 5 6 k = 1×3 logical array 1 0 1 U = 2 3 8 6 0 H = 4 3 2 2 0 A = 5 k = logical 1 U = 2 3 8 6 5 H = 4 3 2 2 1 A = 1×0 empty double row vector

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

num = 10 U = 0 0 0 0 0 0 0 0 0 0 H = 0 0 0 0 0 0 0 0 0 0 k = 1×10 logical array 1 0 0 0 0 0 0 0 0 0 U = 100 0 0 0 0 0 0 0 0 0 H = 1 0 0 0 0 0 0 0 0 0 A = 89 78 67 56 45 34 23 12 1 k = 1×9 logical array 1 0 0 0 0 0 0 0 0 U = 100 89 0 0 0 0 0 0 0 0 H = 1 1 0 0 0 0 0 0 0 0 A = 78 67 56 45 34 23 12 1 k = 1×8 logical array 1 0 0 0 0 0 0 0 U = 100 89 78 0 0 0 0 0 0 0 H = 1 1 1 0 0 0 0 0 0 0 A = 67 56 45 34 23 12 1 k = 1×7 logical array 1 0 0 0 0 0 0 U = 100 89 78 67 0 0 0 0 0 0 H = 1 1 1 1 0 0 0 0 0 0 A = 56 45 34 23 12 1 k = 1×6 logical array 1 0 0 0 0 0 U = 100 89 78 67 56 0 0 0 0 0 H = 1 1 1 1 1 0 0 0 0 0 A = 45 34 23 12 1 k = 1×5 logical array 1 0 0 0 0 U = 100 89 78 67 56 45 0 0 0 0 H = 1 1 1 1 1 1 0 0 0 0 A = 34 23 12 1 k = 1×4 logical array 1 0 0 0 U = 100 89 78 67 56 45 34 0 0 0 H = 1 1 1 1 1 1 1 0 0 0 A = 23 12 1 k = 1×3 logical array 1 0 0 U = 100 89 78 67 56 45 34 23 0 0 H = 1 1 1 1 1 1 1 1 0 0 A = 12 1 k = 1×2 logical array 1 0 U = 100 89 78 67 56 45 34 23 12 0 H = 1 1 1 1 1 1 1 1 1 0 A = 1 k = logical 1 U = 100 89 78 67 56 45 34 23 12 1 H = 1 1 1 1 1 1 1 1 1 1 A = 1×0 empty double row vector num = 10 U = 0 0 0 0 0 0 0 0 0 0 H = 0 0 0 0 0 0 0 0 0 0 k = 1×10 logical array 1 0 0 0 0 0 0 0 0 0 U = 100 0 0 0 0 0 0 0 0 0 H = 1 0 0 0 0 0 0 0 0 0 A = 89 78 67 56 45 34 23 12 1 k = 1×9 logical array 1 0 0 0 0 0 0 0 0 U = 100 89 0 0 0 0 0 0 0 0 H = 1 1 0 0 0 0 0 0 0 0 A = 78 67 56 45 34 23 12 1 k = 1×8 logical array 1 0 0 0 0 0 0 0 U = 100 89 78 0 0 0 0 0 0 0 H = 1 1 1 0 0 0 0 0 0 0 A = 67 56 45 34 23 12 1 k = 1×7 logical array 1 0 0 0 0 0 0 U = 100 89 78 67 0 0 0 0 0 0 H = 1 1 1 1 0 0 0 0 0 0 A = 56 45 34 23 12 1 k = 1×6 logical array 1 0 0 0 0 0 U = 100 89 78 67 56 0 0 0 0 0 H = 1 1 1 1 1 0 0 0 0 0 A = 45 34 23 12 1 k = 1×5 logical array 1 0 0 0 0 U = 100 89 78 67 56 45 0 0 0 0 H = 1 1 1 1 1 1 0 0 0 0 A = 34 23 12 1 k = 1×4 logical array 1 0 0 0 U = 100 89 78 67 56 45 34 0 0 0 H = 1 1 1 1 1 1 1 0 0 0 A = 23 12 1 k = 1×3 logical array 1 0 0 U = 100 89 78 67 56 45 34 23 0 0 H = 1 1 1 1 1 1 1 1 0 0 A = 12 1 k = 1×2 logical array 1 0 U = 100 89 78 67 56 45 34 23 12 0 H = 1 1 1 1 1 1 1 1 1 0 A = 1 k = logical 1 U = 100 89 78 67 56 45 34 23 12 1 H = 1 1 1 1 1 1 1 1 1 1 A = 1×0 empty double row vector

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.

num = 21 U = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 k = 1×100 logical array Columns 1 through 44 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 Columns 45 through 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 89 through 100 0 0 0 0 0 0 0 1 0 0 0 0 U = -2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 9 4 -1 10 0 -1 7 10 0 -10 -1 6 -9 9 -6 10 -7 -1 -10 2 -6 -5 6 9 -8 9 5 -9 -9 Columns 30 through 58 4 -5 -8 -8 3 -6 0 -9 0 10 -3 9 -10 7 6 2 -1 -3 5 -7 -9 -10 3 6 8 10 6 -8 -3 Columns 59 through 87 0 -1 -3 -1 -3 -1 -4 0 -5 -4 3 7 -3 -4 -8 -6 4 -9 -1 -5 -10 1 4 -5 8 5 -1 9 1 Columns 88 through 95 -8 -5 -1 4 -3 0 -5 -5 k = 1×95 logical array Columns 1 through 44 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 Columns 45 through 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 Columns 89 through 95 0 0 0 0 0 0 0 U = -2 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 4 -1 10 0 -1 7 10 0 -10 -1 6 -9 -6 10 -7 -1 -10 2 -6 -5 6 -8 5 -9 -9 4 -5 -8 -8 Columns 30 through 58 3 -6 0 -9 0 10 -3 -10 7 6 2 -1 -3 5 -7 -9 -10 3 6 8 10 6 -8 -3 0 -1 -3 -1 -3 Columns 59 through 87 -1 -4 0 -5 -4 3 7 -3 -4 -8 -6 4 -9 -1 -5 -10 1 4 -5 8 5 -1 1 -8 -5 -1 4 -3 0 Columns 88 through 89 -5 -5 k = 1×89 logical array Columns 1 through 44 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 45 through 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 Column 89 0 U = -2 9 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 -1 10 0 -1 7 10 0 -10 -1 6 -9 -6 10 -7 -1 -10 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 Columns 30 through 58 0 -9 0 10 -3 -10 7 6 2 -1 -3 5 -7 -9 -10 3 6 8 10 6 -8 -3 0 -1 -3 -1 -3 -1 -4 Columns 59 through 84 0 -5 -4 3 7 -3 -4 -8 -6 -9 -1 -5 -10 1 -5 8 5 -1 1 -8 -5 -1 -3 0 -5 -5 k = 1×84 logical array Columns 1 through 44 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 Columns 45 through 84 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 U = -2 9 4 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 10 0 7 10 0 -10 6 -9 -6 10 -7 -10 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 0 -9 0 10 Columns 30 through 58 -3 -10 7 6 2 -3 5 -7 -9 -10 3 6 8 10 6 -8 -3 0 -3 -3 -4 0 -5 -4 3 7 -3 -4 -8 Columns 59 through 73 -6 -9 -5 -10 1 -5 8 5 1 -8 -5 -3 0 -5 -5 k = 1×73 logical array Columns 1 through 44 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Columns 45 through 73 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U = -2 9 4 -1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 11 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 0 7 0 -10 6 -9 -6 -7 -10 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 0 -9 0 -3 -10 7 6 Columns 30 through 58 2 -3 5 -7 -9 -10 3 6 8 6 -8 -3 0 -3 -3 -4 0 -5 -4 3 7 -3 -4 -8 -6 -9 -5 -10 1 Columns 59 through 68 -5 8 5 1 -8 -5 -3 0 -5 -5 k = 1×68 logical array Columns 1 through 44 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 Columns 45 through 68 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 U = -2 9 4 -1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 11 5 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 7 -10 6 -9 -6 -7 -10 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 -9 -3 -10 7 6 2 -3 5 -7 Columns 30 through 58 -9 -10 3 6 8 6 -8 -3 -3 -3 -4 -5 -4 3 7 -3 -4 -8 -6 -9 -5 -10 1 -5 8 5 1 -8 -5 Columns 59 through 61 -3 -5 -5 k = 1×61 logical array Columns 1 through 44 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Columns 45 through 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U = -2 9 4 -1 10 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 11 5 7 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 -10 6 -9 -6 -7 -10 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 -9 -3 -10 6 2 -3 5 -7 -9 -10 Columns 30 through 58 3 6 8 6 -8 -3 -3 -3 -4 -5 -4 3 -3 -4 -8 -6 -9 -5 -10 1 -5 8 5 1 -8 -5 -3 -5 -5 k = 1×58 logical array Columns 1 through 44 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 45 through 58 0 0 0 1 0 0 0 0 0 0 0 0 0 0 U = -2 9 4 -1 10 0 7 -10 0 0 0 0 0 0 0 0 0 0 0 0 0 H = 5 6 5 11 5 7 3 5 0 0 0 0 0 0 0 0 0 0 0 0 0 A = Columns 1 through 29 6 -9 -6 -7 2 -6 -5 6 -8 5 -9 -9 -5 -8 -8 3 -6 -9 -3 6 2 -3 5 -7 -9 3 6 8 6 Columns 30 through 53 -8 -3 -3 -3 -4 -5 -4 3 -3 -4 -8 -6 -9 -5 1 -5 8 5 1 -8 -5 -3 -5 -5 k = 1×53 logical array Columns 1 through 44 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1...