# Time 1, Exercise 3: a moon tally on a bone # A tally maker notches one mark a day. Month length is 29.530589 days. # 1) If every month is counted as 29, 30 or 29.5 days, how far has the tally # drifted from the Moon after 12 months, and after how many months is it a # whole day out? # 2) If you alternate 29- and 30-day months, how does the error behave? MONTH = 29.530589 def drift_days(months, tally_length): """How many days a tally of fixed month length has drifted from the Moon.""" return months * (MONTH - tally_length) for length in (29, 30, 29.5): print("tally", length, "-> drift after 12 months:", round(drift_days(12, length), 3), "days") for length in (29, 30, 29.5): months_to_one_day = 1 / abs(MONTH - length) print("tally", length, "-> one day off after", round(months_to_one_day, 2), "months") error = 0.0 length = 29 for month in range(1, 13): error += MONTH - length length = 30 if length == 29 else 29 print(month, round(error, 3)) # Output when run: # tally 29 -> drift after 12 months: 6.367 days # tally 30 -> drift after 12 months: -5.633 days # tally 29.5 -> drift after 12 months: 0.367 days # tally 29 -> one day off after 1.88 months # tally 30 -> one day off after 2.13 months # tally 29.5 -> one day off after 32.69 months # 1 0.531 # 2 0.061 # 3 0.592 # 4 0.122 # 5 0.653 # 6 0.184 # 7 0.714 # 8 0.245 # 9 0.775 # 10 0.306 # 11 0.836 # 12 0.367 # # Reading the output: counting every month as 29 days lags the Moon by about # 6.4 days in a year; counting 30 runs ahead by 5.6. A fixed 29.5 is far # better: 0.37 days in 12 months, a whole day out after about 33 months. The # alternating tally (29, 30, 29, 30...) is the same as using 29.5 on average: # the error swings up and down by about half a day but creeps upward by # 0.061 days per pair of months, ending at 0.367 days after 12 months. # Real calendars therefore insert an occasional extra day. This is the same # kind of fix that leap years make for the solar year.