Cody

# Problem 44768. Muphry's Law of MATLAB

Solution 1720272

Submitted on 4 Feb 2019 by Alfonso Nieto-Castanon
• Size: 57
• 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
x = [67 58 3596]; y_correct = [62 58]; assert(isequal(muphry(x),y_correct))

2   Pass
x = [58 67 3596]; y_correct = [58 62]; assert(isequal(muphry(x),y_correct))

3   Pass
x=[11 13 363]; y_correct = [11 33]; assert(isequal(muphry(x),y_correct))

4   Pass
x=[2 3 4 5 16 3120]; y_correct = [2 3 4 5 26]; assert(isequal(muphry(x),y_correct))

5   Pass
x=[12345 23456 166114320]; y_correct = [12345 13456]; assert(isequal(muphry(x),y_correct))

6   Pass
x=[11 22 132]; y_correct = [11 12]; assert(isequal(muphry(x),y_correct))

7   Pass
x=[12 22 252]; y_correct = [12 21]; assert(isequal(muphry(x),y_correct))

8   Pass
x=[2 3 4 5 16 2688]; y_correct=[2 3 4 7 16]; assert(isequal(muphry(x),y_correct))

9   Pass
for flag=1:1000 p1=10; p2=10; p3=10; while or((p1==p3),or((p2==p3),(p1==p2))) p1=[ceil(9*rand) floor(10*rand(1,4))]; p2=[ceil(9*rand) floor(10*rand(1,4))]; if rand>0.5 p3=p1; changed=1; else p3=p2; changed=2; end n=ceil(4*rand)+1; if p3(n)==9 p3(n)=0; else p3(n)=p3(n)+1; end p1p=polyval(p1,10); p2p=polyval(p2,10); p3p=polyval(p3,10); end if changed==1 x=[p1p p2p p3p*p2p]; else x=[p1p p2p p1p*p3p]; end xval=muphry(x); if changed==2 assert(isequal(xval,[p1p p3p])) else assert(isequal(xval,[p3p p2p])) end end

### Community Treasure Hunt

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

Start Hunting!