Cody

Solution 2071010

Submitted on 27 Dec 2019 by Asif Newaz
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
d=[1 2 2 2 1 2 1 2]; vector=[1 2 3 4 5 6 7 8]; new_vec=[1 4 6 8 9 12 13 16]; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

vec2 = 2 4 6 8 10 12 14 16 a = 1 5 7 vec2 = 1 4 6 8 9 12 13 16 filetext = 'function vec2= change_direction(vector,d) vec2=2*vector a=find(d==1) vec2(a)=2*vector(a)-1 end %This code written by profile_id 16549154 '

2   Pass
d=[ones(1,5) 2*ones(1,4) ones(1,3)]; vector=1:length(d); new_vec=[1 3 5 7 9 12 14 16 18 19 21 23]; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

vec2 = 2 4 6 8 10 12 14 16 18 20 22 24 a = 1 2 3 4 5 10 11 12 vec2 = 1 3 5 7 9 12 14 16 18 19 21 23 filetext = 'function vec2= change_direction(vector,d) vec2=2*vector a=find(d==1) vec2(a)=2*vector(a)-1 end %This code written by profile_id 16549154 '

3   Pass
d=ones(1,6); vector=[1 2 3 4 5 6]; new_vec=2*vector-1; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

vec2 = 2 4 6 8 10 12 a = 1 2 3 4 5 6 vec2 = 1 3 5 7 9 11 filetext = 'function vec2= change_direction(vector,d) vec2=2*vector a=find(d==1) vec2(a)=2*vector(a)-1 end %This code written by profile_id 16549154 '

4   Pass
d=ones(1,50); vector=zeros(1,50); new_vec=vector-1; assert(isequal(change_direction(vector,d),new_vec)) filetext = fileread('change_direction.m') assert(isempty(strfind(filetext, 'if')))

vec2 = Columns 1 through 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 31 through 50 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 vec2 = Columns 1 through 30 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 Columns 31 through 50 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 filetext = 'function vec2= change_direction(vector,d) vec2=2*vector a=find(d==1) vec2(a)=2*vector(a)-1 end %This code written by profile_id 16549154 '

Suggested Problems

More from this Author21