In Case Sudoku Is Getting Boring
Problem Statement: Find an algorithm that will generate the year, given the number of an arbitrary day after the beginning of an epoch on an arbitrary planet, based on parameters for the relevant variables.
Example: The mean synodic day on Earth (midday to midday) is 24 hours 0 minutes 0 seconds. The period of solation (AKA tropical year, the mean time between vernal equinoxes) is 365.2422 days. The conventional (calendar) year is 365 days. This undercorrects for the tropical year by 0.2422 days, so in every 4th year (a leap year) an extra day is inserted, bringing that particular year up to 366 days and bringing the 4-year average up to 365.25 days. This overcorrects for the tropical year by 0.0078 days, so in every 100th year, after 0.78 days of overcorrection have accumulated, a 2nd-order correction is instituted, and a leap year is omitted. This results in an undercorrection of 0.22 days, which is offset by having a 3rd-order correction every 400 years, when the leap year occurs after all.
Therefore, if we assume the current epoch begins on 2001 Jan. 1, in what year does Day 1461 occur? The brute-force method is to start with 1461 and subtract off the number of days in each consecutive year until we run out. Thus 1461 - 365 (2001) = 1096 – 365 (2002) = 731 - 365 (2003) = 366 - 366 (2004) = 0. The tricky part comes in knowing that, in 2004, we need to subtract 366 instead of 365.
But this approach is inelegant, tedious for things like Day 1,000,000, and peculiar to only a single planet. We seek a general formula based on no advance knowledge of planetary conditions.
(1) Deal only with the 1st-order corrections; don't worry about higher-order corrections.
(2) Assume that the granularity of days to years is ~2-4 orders of magnitude. Any finer granularity, and the problem becomes trivial. Any coarser granularity, and you end up with things like the 3-6-8-11-14-17-19 cycle of the Jewish lunisolar calendar, which verge on the arbitrary.
(3) Assume that the entire 1st-order correction is applied to a single year at the end of each leap-year cycle which, for convenience, you may assume is evenly divisible by the number of years in the cycle.
(4) The number of corrective days must be an integer.
(5) The number of corrective days may be other than 1.
(6) The number of corrective days may be greater or less than 0.
(7) Use only the functions (notably including "mod") available to an ordinary computer spreadsheet or programming language; no calculus.
(8) OK, do try to figure out how to deal with 2nd-order corrections.