That is a fun test suite. :P
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
x = [0 0 0 0 0 0 1 1 1 1 1 1;
0 0 0 1 1 1 0 0 0 1 1 1;
0 1 1 0 1 1 0 1 1 0 1 1;
0 1 0 1 0 1 0 1 0 1 0 1];
y = [0 0 1 0 0 1 1 1 0 1 1 0];
assert(isequal(arr_xor(x),y))
assert(isequal(arr_xor(x'),zeros(1,4)))
|
2 | Pass |
%%
x = randi([0 1],4,12);
y = x(1,:);
for k=2:4
y = xor(y,x(k,:));
end
assert(isequal(arr_xor(x),y))
|
3 | Pass |
%% optional:
% optional logical output
try
assert(islogical(arr_xor(randi([0 1],6,10))))
penalty = 0;
catch
disp('output is not logical, +15 points of penalty')
penalty = 15;
end
% optional - dim
x = randi([0 1],10);
try
assert(isequal(arr_xor(x),arr_xor(x ,1)))
assert(isequal(arr_xor(x),arr_xor(x',2)'))
catch
disp('operating dimention not implemented. +15 points of penalty')
penalty = penalty+15;
end
% optional - correct for singular dimention
try
assert(isequal(arr_xor(1),1))
assert(isequal(arr_xor([0 0 1 1 0]),0))
assert(isequal(arr_xor([0;1;1;1;0]),1))
catch
disp('incorrect work for vectors, +10 points of penalty');
penalty=penalty+10;
end
% format conversion
try
assert(isequal(arr_xor(['MATLAB';'matlab']'),[0 0]))
catch
disp('no conversion from char, +2 points of penalty' )
penalty=penalty+2;
end
try
assert(all(arr_xor(randi(5,5))))
assert(~any(arr_xor(randi(6,6))))
catch
disp('no conversion from double, +5 points of penalty' )
penalty=penalty+5;
end
for l=1:4
stime(l)=tic;
for k=2:750
[~]=arr_xor(randi([0 1],k));
end
time(l)=toc(stime(l));
end
time=min(time);
disp(['elapsed time is ' num2str(time*1000) ' ms.'])
%score calculation
t = mtree('arr_xor.m','-file');
size = length(t.nodesize);
feval(@assignin,'caller','score',size + penalty + round(time*5));
elapsed time is 4770.824 ms.
|
54303 Solvers
Make the vector [1 2 3 4 5 6 7 8 9 10]
35560 Solvers
2261 Solvers
Arrange vector in ascending order
624 Solvers
465 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!