Cody

Problem 2281. Array ex-OR

Solution 3290548

Submitted on 20 Oct 2020 by Erind Veruari
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 = [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 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));

operating dimention not implemented. +15 points of penalty incorrect work for vectors, +10 points of penalty elapsed time is 2600.046 ms.

Suggested Problems

More from this Author41

Community Treasure Hunt

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

Start Hunting!