#!/usr/bin/env sage -python # # ComputeEaster: Compute date of Easter Sunday in the Gregorian calendar. # # Adapted from an example in _Introducing Fortran 95_ by Chivers and Sleighthome, # which was itself adapted from an example by Donald Knuth. # # Stephen Forrest, http://wandership.ca/ def ComputeEaster(Year): Metcyc = (Year % 19) + 1 if Year <= 1582: Day = (5*Year) // 4 Epact = ((11*Metcyc-4) % 30) + 1 else: Century = (Year // 100)+1 Error1 = ((3*Century) // 4)-12 Error2 = ((8*Century+5) // 25)-5 Day = ((5*Year) // 4)-Error1-10 Temp = 11*Metcyc + 20 + Error2 - Error1 Epact = Temp % 30 if Epact <= 0: Epact = 30 + Epact if ((Epact==25 and Metcyc>11) or Epact==24): Epact = Epact+1 Luna = 44 - Epact if Luna < 21: Luna = Luna+30 Luna = Luna+7 - ((Day+Luna) % 7) if Luna > 31: return( 'April %(date)d' % {'date': Luna-31} ) else: return( 'March %(date)d' % {'date': Luna} ) # Examples print ComputeEaster( 1938 ) print ComputeEaster( 2007 )