Cody

Problem 44342. Spot the First Occurrence of 5

Solution 1937460

Submitted on 15 Sep 2019 at 16:35 by ChanXy
• Size: 7
• This is the leading solution.
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   Pass
x = 2:2:20; y_correct = 0; assert(isequal(locOf5(x),y_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In locOf5 (line 2) In ScoringEngineTestPoint2 (line 3) In solutionTest (line 5)]

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

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In locOf5 (line 2) In ScoringEngineTestPoint3 (line 3) In solutionTest (line 7)]

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

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In locOf5 (line 2) In ScoringEngineTestPoint4 (line 5) In solutionTest (line 9)]

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

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In locOf5 (line 2) In ScoringEngineTestPoint5 (line 3) In solutionTest (line 11)]

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

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In locOf5 (line 2) In ScoringEngineTestPoint6 (line 7) In solutionTest (line 13)]