Cody

# Problem 44342. Spot the First Occurrence of 5

Solution 2758837

Submitted on 30 Jul 2020
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
assessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','locOf5.m')

2   Fail
x = 2:2:20; y_correct = 0; assert(isequal(locOf5(x),y_correct))

m = 1 n = 10 z = 1×0 empty double row vector

Index exceeds the number of array elements (0). Error in locOf5 (line 5) y(r) = z(1) Error in Test2 (line 3) assert(isequal(locOf5(x),y_correct))

3   Fail
x = rot90(1:10); y_correct = 6; assert(isequal(locOf5(x),y_correct))

m = 10 n = 1 z = []

Index exceeds the number of array elements (0). Error in locOf5 (line 5) y(r) = z(1) Error in Test3 (line 3) assert(isequal(locOf5(x),y_correct))

4   Fail
x = [1 2 5 5 9 1 5 6 5]; y_correct = [2 0 1]; assert(isequal(locOf5(x),y_correct))

m = 3 n = 3 z = 3 y = 3 z = 1 y = 3 1 z = 1 3 y = 3 1 1

Assertion failed.

5   Fail
x = magic(5); y_correct = [0 2 0 0 0]; assert(isequal(locOf5(x),y_correct))

m = 5 n = 5 z = 1×0 empty double row vector

Index exceeds the number of array elements (0). Error in locOf5 (line 5) y(r) = z(1) Error in Test5 (line 3) assert(isequal(locOf5(x),y_correct))

6   Fail
x = [1 2 3 4 5; 5 4 3 2 1 2 3 5 2 1 1 5 2 6 8 3 5 2 2 5]; y_correct = [2 4 3 0 1]; assert(isequal(locOf5(x),y_correct)) % %% % x = randi([-10,10],20,1e6); % x(x==5) = 0; % p = sort(randi([0 size(x,1)],5,size(x,2))); % y_correct = p(1,:); % p(2:end,~y_correct) = 0; % [~,col,v] = find(p); % x((col-1)*size(x,1)+v) = 5; % assert(isequal(locOf5(x),y_correct))

m = 5 n = 5 z = 5 y = 5 z = 1 y = 5 1 z = 3 y = 5 1 3 z = 2 y = 5 1 3 2 z = 2 5 y = 5 1 3 2 2

Assertion failed.