Problem 1319. Leap years on other planets
A year is a leap year if it is divisible by 4, but not if it is divisible by 100, unless it is also divisible by 400. This means the average length of a calendar year is
365 + 1/4 - 1/100 + 1/400 = 365.2425 days
which approximately matches the length of an actual year (the number of days it takes the earth to go around the sun once).
Given p, the length of a year on another planet in units of days on that planet, and given that normal years have N days and leap years have N+1 days, where N=floor(p), find integer vector m>0 defining leap years [years divisible by m(1) are leap years, but years divisible by m(2) are not, unless they are divisible by m(3), but then not if they are divisible by m(4), etc.] so that
p = N + 1/m(1) - 1/m(2) + 1/m(3) - 1/m(4) + ...
Include enough terms so that this is correct to four decimal places. Note that m(i+1) should be an integer multiple of m(i). Results are not necessarily unique. For example, if p=365.2425 then m=[4 100 400] is an exact answer, but m=[4 132 13068] also could be used (and [4 132] gives 365.2424, a better approximation than [4 100], which gives 365.2400).
Solution Stats
Problem Comments
-
1 Comment
The test cases were calculated from actual data (length of day and tropical orbit period) at www.heavens-above.com, but they are not necessarily as well-defined or accurately known as the number of decimal places used here might imply.
Solution Comments
Show commentsProblem Recent Solvers56
Suggested Problems
-
3259 Solvers
-
Matrix with different incremental runs
500 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
475 Solvers
-
81 Solvers
-
913 Solvers
More from this Author11
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!