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 215159

Submitted on 10 Mar 2013 by Alfonso Nieto-Castanon

Correct

45Size
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
Code Input and Output
1
Pass
 
N={'Mercury','Venus','Earth','Mars','Jupiter',...
   'Saturn','Uranus','Neptune','Pluto'};
P=[0.5000 1.9246 365.2425 668.5950 10471.0182 ...
   24204.8198 42582.9327 89087.3743 14183.7398];
for i=1:9
   p=P(i);
   m=leapsequence(p);
   n=numel(m);
   r=dot(1./m,(-1).^(0:n-1));
   disp([N{i} ' p=' num2str(p,'%0.6f') ...
    ' r=' num2str(r,'%0.6f') ' m=' mat2str(m)])
   assert(abs(floor(p)+r-p)<=0.00005);
   assert(all(m>0))
   assert(all(mod(m,1)==0))
   assert(all(mod([m 0],[1 m])==0))
end
Mercury p=0.500000 r=0.500000 m=2
Venus p=1.924600 r=0.924600 m=[1 13 650 65000]
Earth p=365.242500 r=0.242500 m=[4 132 13068 1306800]
Mars p=668.595000 r=0.595000 m=[1 2 10 200]
Jupiter p=10471.018200 r=0.018200 m=[54 3132 1302912 814320000]
Saturn p=24204.819800 r=0.819800 m=[1 5 50 5000]
Uranus p=42582.932700 r=0.932700 m=[1 14 238 13566 1641486 210110208 192881170944]
Neptune p=89087.374300 r=0.374300 m=[2 6 24 1416 160008 28481424 9227981376 6385763112192]
Pluto p=14183.739800 r=0.739800 m=[1 3 12 96 4608 2875392 1797120000 1604828160000]