# Time 3, Exercise 3: the 30-year tabular Islamic calendar YEAR = 365.2422 MONTH = 29.530589 LEAP = {2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29} lengths = [355 if y in LEAP else 354 for y in range(1, 31)] total = sum(lengths) print("days in 30 years:", total, "| average year", round(total / 30, 4), "| average month", round(total / 360, 6)) print("true month:", MONTH, "| error per month", round(total / 360 - MONTH, 6), "days") error_per_cycle = total - 360 * MONTH print("error per 30-year cycle:", round(error_per_cycle, 4), "days") print("years until one day out:", round(30 / abs(error_per_cycle))) # Approximate Gregorian year in which a given Islamic year begins. ratio = (total / 30) / YEAR print("Islamic year / solar year:", round(ratio, 6)) for h in (1, 100, 1000, 1447): print(h, "AH begins around", round(622.54 + (h - 1) * ratio, 1)) # Output when run: # days in 30 years: 10631 | average year 354.3667 | average month 29.530556 # true month: 29.530589 | error per month -3.3e-05 days # error per 30-year cycle: -0.012 days # years until one day out: 2492 # Islamic year / solar year: 0.970224 # 1 AH begins around 622.5 # 100 AH begins around 718.6 # 1000 AH begins around 1591.8 # 1447 AH begins around 2025.5 # # Reading the output: the 30-year cycle lasts 10631 days, an average month of # 29.530556 days against the true 29.530589, so it needs a day's correction only # every 2500 years or so. The Islamic year is 0.97 of a solar year, which is why # 1447 AH starts in 2025 although only 1403 solar years have passed since 622.