#!/usr/bin/python """ Output the date of Easter in the western churches for any year in the range 1583 to 99999 AD inclusive. From Donald E. Knuth, "The Art of Computer Programming, Volume 1: Fundamental Algorithms", 2nd ed. (1973), pp. 155-156. """ import sys year = 2025 if year <= 1582 or year >= 100000: sys.stderr.write("Sorry, year is out of range.\n") sys.exit(1) #Unsuccessful termination. golden = year % 19 + 1 #Metonic cycle century = year // 100 + 1 #the century that contains the year x = 3 * century // 4 - 12 #number of times leap year was cancelled z = (8 * century + 5) // 25 - 5 #sync with Moon's orbit day = 5 * year // 4 - x - 10 epact = (11 * golden + 20 + z - x) % 30 #age of moon on Jan 1 if epact < 0: epact += 30 #Make sure epact is non-negative. if epact == 24 or epact == 25 and golden > 11: ++epact n = 44 - epact #The nth day of March is a full moon. if n < 21: #March 21 is the vernal equinox. n += 30 #Get the full moon after the equinox. n += 7 - (day + n) % 7 #Advance to the next Sunday. print("Easter is on Sunday, ", end = "") if n <= 31: print("March", n, end = "") else: print("April", n - 31, end = "") print(",", year, ".") sys.exit(0) #Successful termination.