Cody

Problem 980. Unique values without using UNIQUE function

Solution 1719142

Submitted on 1 Feb 2019 by Nikolaos Nikolaou
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
filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'unique'))) assert(isempty(strfind(filetext, 'stable'))) A = [9 2 9 5]; assert(isequal(your_fcn_name(A),unique(A,'stable')))

filetext = 'function y = your_fcn_name(x) i=1; while isempty(x)~=1 t(i)=x(1) x(x==x(1))=[] i=i+1 end y=t end %This code written by profile_id 7310613 ' t = 9 x = 2 5 i = 2 t = 9 2 x = 5 i = 3 t = 9 2 5 x = 1×0 empty double row vector i = 4 y = 9 2 5

2   Pass
x = [42 1 1 1 42 17 17]; assert(isequal(your_fcn_name(x),unique(x,'stable')))

t = 42 x = 1 1 1 17 17 i = 2 t = 42 1 x = 17 17 i = 3 t = 42 1 17 x = 1×0 empty double row vector i = 4 y = 42 1 17

3   Pass
x = rand(1,25); assert(isequal(your_fcn_name(x),unique(x,'stable')))

t = 0.0789 x = Columns 1 through 18 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 Columns 19 through 24 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 2 t = 0.0789 0.1704 x = Columns 1 through 18 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 Columns 19 through 23 0.2669 0.8496 0.7494 0.9091 0.4002 i = 3 t = 0.0789 0.1704 0.1061 x = Columns 1 through 18 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 Columns 19 through 22 0.8496 0.7494 0.9091 0.4002 i = 4 t = 0.0789 0.1704 0.1061 0.8066 x = Columns 1 through 18 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 Columns 19 through 21 0.7494 0.9091 0.4002 i = 5 t = 0.0789 0.1704 0.1061 0.8066 0.1529 x = Columns 1 through 18 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 Columns 19 through 20 0.9091 0.4002 i = 6 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 x = Columns 1 through 18 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 Column 19 0.4002 i = 7 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 x = 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 8 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 x = 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 9 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 x = 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 10 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 x = 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 11 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 x = 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 12 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 x = 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 13 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 x = 0.2084 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 14 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 x = 0.3777 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 15 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 x = 0.1460 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 16 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 x = 0.3403 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 17 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 x = 0.0751 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 18 t = 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 x = 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 19 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Column 19 0.3643 x = 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 i = 20 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 20 0.3643 0.4597 x = 0.2669 0.8496 0.7494 0.9091 0.4002 i = 21 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 21 0.3643 0.4597 0.2669 x = 0.8496 0.7494 0.9091 0.4002 i = 22 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 22 0.3643 0.4597 0.2669 0.8496 x = 0.7494 0.9091 0.4002 i = 23 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 23 0.3643 0.4597 0.2669 0.8496 0.7494 x = 0.9091 0.4002 i = 24 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 24 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 x = 0.4002 i = 25 t = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 25 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002 x = 1×0 empty double row vector i = 26 y = Columns 1 through 18 0.0789 0.1704 0.1061 0.8066 0.1529 0.6774 0.7496 0.8904 0.5937 0.4675 0.0207 0.6497 0.7533 0.2084 0.3777 0.1460 0.3403 0.0751 Columns 19 through 25 0.3643 0.4597 0.2669 0.8496 0.7494 0.9091 0.4002