Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 275853

Submitted on 8 Jul 2013 by Paul Berglund

Correct

38Size
Leading solution size is 36.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
!cp leftovers.m safe
!rm *.*
!mv safe leftovers.m
!rm @*
% Clean user's function from some known jailbreaking mechanisms
fid = fopen('leftovers.m');
st = regexprep(char(fread(fid)'), '!', 'error(''No shell commands!''); %');
st = regexprep(st, 'feval', 'error(''No fancy functions!''); %');
st = regexprep(st, 'str2func', 'error(''No fancy functions!''); %');
st = regexprep(st, 'regex', 'error(''No fancy functions!''); %');
st = regexprep(st, 'system', 'error(''No shell commands!''); %');
st = regexprep(st, 'dos', 'error(''No shell commands!''); %');
st = regexprep(st, 'unix', 'error(''No shell commands!''); %');
st = regexprep(st, 'perl', 'error(''No external languages commands!''); %');
st = regexprep(st, 'java', 'error(''No external languages commands!''); %');
st = regexprep(st, 'assert', 'error(''No overwriting!''); %');
fclose(fid)
fid = fopen('leftovers.m' , 'w');
fwrite(fid,st);
fclose(fid)
rm: cannot remove `@*': No such file or directory
ans =
     0
ans =
     0
2
Pass
 
%%
V1 = [2 3] ; V2 = [1 2];; y_correct = 5; assert(isequal(leftovers(V1,V2),y_correct))

                    
3
Pass
 
%%
V1=[3 5 7] ; V2=[1 2 3]; y_correct = 52; assert(isequal(leftovers(V1,V2),y_correct))

                    
4
Pass
 
%%
V1=[3 4 5] ; V2=[2 3 1]; y_correct = 11; assert(isequal(leftovers(V1,V2),y_correct))

                    
5
Pass
 
%%
V1=[4 9 25] ; V2=[3 2 7]; y_correct = 407; assert(isequal(leftovers(V1,V2),y_correct))

                    
6
Pass
 
%%
V1=[9 10 77] ; V2=[1 2 69]; y_correct = 6922; assert(isequal(leftovers(V1,V2),y_correct))

                    
7
Pass
 
%%
a=primes(30);
b=ceil(8*rand()+2)
V1=a(1:b);V2=1:b;
y_correct=[23 53 1523 29243 299513 4383593 188677703 5765999453];
assert(isequal(leftovers(V1,V2),y_correct(b-2)))
b =
     4
8
Pass
 
%%
V1=[leftovers([6 35],[3 9]) leftovers([3 5 7],[1 3 1])];
assert(isequal(leftovers(V1,V1-8),379))

                    
9
Pass
 
%%
% Discourage the for x=1:inf loops
V1=[74 93 145 161 209 221]; V2=[66 85 137 153 201 213];
y_correct=7420738134802;
assert(isequal(leftovers(V1,V2),y_correct))

                    
10
Pass
 
%%
% Discourage the for x=1:inf loops
V1=[17 82 111 155 203 247 253] ; V2=[11 50 68 95 124 150 154];
y_correct=59652745309190;
assert(isequal(leftovers(V1,V2),y_correct))