Sunday, January 05, 2014

[qupqknlc] Greedy leap years

Leap day every 4 years.
Omit leap day every 33*4=132 years.
Keep leap day every 100*33*4=13200 years.

This sequence of multipliers [4,33,100] were found by the greedy method. The entire cycle has the same average year length as the Gregorian calendar = 365 + 97/400 days, which uses multipliers [4,25,4]. We alternate between keeping and omitting leap days at each larger multiplier.

countDays::Integer->[Integer]->Integer->Integer;
countDays accum (h:t) offset = countDays (accum*h+offset) t (negate offset);
countDays accum [] _ = accum;
averageYear :: [Integer] -> Rational;
averageYear leapPattern = (countDays 365 leapPattern 1) % (product leapPattern)

What is going on such that averageYear [4,33,100] == averageYear [4,25,4]? Find a set of multipliers which minimizes the product, i.e., cycle length. I suspect this is related to Egyptian fractions or continued fractions. I suspect that the greedy method yields a sequence which monotonically increases.

Update: these are Pierce expansions, a variant of Engel expansions.

Applying the greedy algorithm to 365 + 71/293 days (as proposed by the Symmetry454 calendar) yields multipliers [4,32,58,97,146,293] for a cycle of 11251521835008 days in 30805635584 years. (This is far less efficient than the 293 year cycle.)

When applied to adding "leap weeks" to the Gregorian calendar, we find the sequence [5,8,10] as reported in calendar based on 7. If we apply leap weeks to the 365+71/293 year-length, we get the sequence [5,8,10,97,146,293].

Some disorganized Haskell code for these calculations.

No comments: