Cody

# Problem 2281. Array ex-OR

Solution 470273

Submitted on 11 Jul 2014 by rifat
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)))

ans = 0 0 1 0 0 1 1 1 0 1 1 0 ans = 0 0 0 0

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

ans = 1 1 0 0 1 0 0 0 1 0 1 0

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

ans = 0 1 0 0 1 0 0 1 1 1 output is not logical, +15 points of penalty ans = 1 0 1 0 0 0 0 1 1 0 operating dimention not implemented. +15 points of penalty ans = 1 ans = 0 ans = 1 ans = 1 1 no conversion from char, +2 points of penalty ans = 0 0 1 1 1 no conversion from double, +5 points of penalty ans = 0 1 ans = 1 0 1 ans = 0 1 0 1 ans = 0 1 0 1 0 ans = 0 1 0 1 0 0 ans = 1 1 1 0 1 0 1 ans = 1 1 1 0 1 0 0 0 ans = 0 1 0 1 0 1 1 0 1 ans = 0 0 1 0 0 1 1 0 0 0 ans = 1 0 0 1 0 1 1 0 1 1 0 ans = 1 0 1 0 0 0 0 0 0 1 0 1 ans = 1 1 1 0 0 0 0 1 0 0 0 0 1 ans = 0 1 0 0 1 1 0 1 1 0 0 1 0 0 ans = 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 ans = 1 1 0 1 0 0 0 1 1 1 0 0 0 0 1 0 ans = Columns 1 through 16 1 0 0 1 1 1 0 1 1 0 0 0 1 0 1 0 Column 17 0 ans = Columns 1 through 16 1 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 Columns 17 through 18 1 1 ans = Columns 1 through 16 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 Columns 17 through 19 0 1 0 ans = Columns 1 through 16 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 Columns 17 through 20 1 1 0 0 ans = Columns 1 through 16 1 0 0 0 1 1 1 1 1 1 1 1 0 1 0 0 Columns 17 through 21 0 0 1 0 1 ans = Columns 1 through 16 1 0 1 1 0 1 0 1 1 0 1 1 0 1 1 0 Columns 17 through 22 0 0 0 1 0 0 ans = Columns 1 through 16 0 1 0 0 0 1 1 0 1 0 0 1 0 1 1 1 Columns 17 through 23 0 1 0 0 1 1 0 ans = Columns 1 through 16 0 0 1 0 0 0 0 0 1 1 0 1 0 1 1 0 Columns 17 through 24 0 1 1 1 0 0 0 0 ans = Columns 1 through 16 1 1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 Columns 17 through 25 0 1 0 0 1 1 1 1 1 ans = Columns 1 through 16 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 Columns 17 through 26 1 0 1 1 0 1 0 0 1 0 ans = Columns 1 through 16 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 1 Columns 17 through 27 1 0 1 1 1 0 0 0 1 0 1 ans = Columns 1 through 16 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 0 Columns 17 through 28 0 1 1 0 1 1 0 1 1 0 0 1 ans = Columns 1 through 16 0 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 Columns 17 through 29 1 0 0 1 1 1 0 0 0 0 0 1 1 ans = Columns 1 through 16 1 1 1 1 1 1 0 0 1 0 0 1 1 1 0 1 Columns 17 through 30 0 1 0 1 0 0 1 0 0 0 1 1 1 1 ans = Columns 1 through 16 0 0 1 1 1 0 1 0 1 1 0 0 0 1 1 0 Columns 17 through 31 1 0 1 1 0 1 0 0 1 0 0 0 1 1 0 ans = Columns 1 through 16 0 0 0 0 1 0 0 1 1 1 1 1 1 0 1 0 Columns 17 through 32 1 1 1 0 0 1 0 0 0 1 1 1 1 0 0 1 ans = Columns 1 through 16 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 0 Columns 17 through 32 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 0 Column 33 0 ans = Columns 1 through 16 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 Columns 17 through 32 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 Columns 33 through 34 1 1 ans = Columns 1 through 16 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 Columns 17 through 32 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 0 Columns 33 through 35 0 1 1 ans = Columns 1 through 16 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 Columns 17 through 32 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1 0 Columns 33 through 36 0 0 1 1 ans = Columns 1 through 16 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 Columns 17 through 32 1 1 1 1 0 0 1 0 1 1 0 1 1 0 0 0 Columns 33 through 37 0 0 1 1 0 ans = Columns 1 through 16 0 0 0 1 1 1 1 0 1 1 1 1 0 1 1 0 Columns 17 through 32 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 Columns 33 through 38 1 1 0 0 0 1 ans = Columns 1 through 16 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 Columns 17 through 32 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 0 Columns 33 through 39 1 1 0 1 1 0 0 ans = Columns 1 through 16 1 0 1 1 0 0 1 1 1 1 1 1 0 0 0 1 Columns 17 through 32 1 1 0 1 1 0 1 0 1 1 0 0 1 0 0 0 Columns 33 through 40 1 1 0 0 0 0 1 1 ans = Columns 1 through 16 0 0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 1 0 0 1 1 0 1 1 1 1 0 1 0 0 0 1 Columns 33 through 41 0 0 0 0 1 1 0 0 1 ans = Columns 1 through 16 0 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 Columns 17 through 32 0 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 Columns 33 through 42 0 0 0 1 0 0 0 1 0 0 ans = Columns 1 through 16 0 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0 Columns 17 through 32 0 0 1 1 1 1 0 0 1 0 0 0 0 0 1 1 Columns 33 through 43 1 0 1 1 0 0 1 1 1 0 0 ans = Columns 1 through 16 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 Columns 17 through 32 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 Columns 33 through 44 1 1 0 0 1 1 1 1 1 1 1 1 ans = Columns 1 through 16 0 0 0 0 1 0 0 1 0 0 1 1 1 0 1 1 Columns 17 through 32 0 0 1 1 0 1 0 1 1 0 0 0 0 1 1 0 Columns 33 through 45 1 0 1 1 1 0 1 1 0 1 0 1 1 ans = Columns 1 through 16 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 Columns 17 through 32 1 1 1 1 0 1 0 1 1 1 0 0 0 0 0 0 Columns 33 through 46 1 0 1 1 1 0 0 1 0 0 1 1 1 0 ans = Columns 1 through 16 0 0 1 0 0 1 1 0 0 1 1 0 1 0 1 1 Columns 17 through 32 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 1 Columns 33 through 47 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 ans = Columns 1 through 16 1 1 1 1 0 0 0 1 0 1 0 1 0 1 1 1 Columns 17 through 32 1 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 Columns 33 through 48 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 1 ans = Columns 1 through 16 1 1 1 1 0 0 0 0 0 0 1 1 0 1 1 0 Columns 17 through 32 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 Columns 33 through 48 0 ...

### Community Treasure Hunt

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

Start Hunting!