RSS Feed

RSS

Comments RSS

A geek celebration of Easter

def EasterDate(y):

# EASTER DATE CALCULATION FOR YEARS 1583 TO 4099

# y is a 4 digit year 1583 to 4099
# d returns the day of the month of Easter
# m returns the month of Easter

# Easter Sunday is the Sunday following the Paschal Full Moon
# (PFM) date for the year

# This algorithm is an arithmetic interpretation of the 3 step
# Easter Dating Method developed by Ron Mallen 1985, as a vast
# improvement on the method described in the Common Prayer Book

# Because this algorithm is a direct translation of the
# official tables, it can be easily proved to be 100% correct

# This algorithm derives values by sequential inter-dependent
# calculations, so … DO NOT MODIFY THE ORDER OF CALCULATIONS!

# The / operator may be unfamiliar – it means integer division
# for example, 30 / 7 = 4 (the remainder is ignored)

#The % operator is for the Modulus operation

# All variables are integer data types

# It’s free! Please do not modify code or comments!
# ==========================================================
#The following is a translation of the BASIC code for the calculation
#of Easter dates to Python 2x. The comments from that code and
#variable names have been preserved. The preceding comments
#have also been preserved with only slight modification and additions
#that are necessary for properly understanding this Python version
#of the program. I encourage the reader to visit following website
#and compare the original BASIC code with the Python code presented
#here.
#The original documentation and code may be found at:
#http://www.assa.org.au/edm.html
#http://www.assa.org.au/edm.html#Computer
#
#Many thanks to the Astronomical Society of South Australia for
#the information that made this possible.
#http://www.assa.org.au/
#FirstDig, Remain19, temp are intermediate results
#tA, tB, tC, tD, tE are table A to E results

FirstDig = y / 100 #first 2 digits of year
Remain19 = y % 19 #remainder of year / 19

#calculate PFM date
temp = (FirstDig – 15)/2 + 202 -11 * Remain19

case1 = (21,24,25,27,28,29,30,31,32,34,35,38)
case2 = (33,36,37,39,40)

if FirstDig in case1:
temp = temp – 1
elif FirstDig in case2:
temp = temp – 2

temp = temp % 30

tA = temp + 21
if temp == 29:
tA = tA -1
if temp == 28 and Remain19 > 10:
tA = tA -1

tB = (tA -19) % 7

tC = (40 – FirstDig) % 4
if tC == 3:
tC = tC + 1
if tC > 1:
tC = tC + 1

temp = y % 100
tD = (temp + temp/4) % 7

tE = ((20 – tB – tC – tD) % 7) + 1
d = tA + tE

if d > 31:
d = d – 31
m = 4
else:
m = 3

return (m,d)

#A simple program using the EasterDate funtcion
year = int(raw_input(“Find the date of Easter for which year(1582-4099)? “))
month_day = EasterDate(year)
months = (‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’,
‘August’, ‘September’, ‘October’, ‘November’, ‘December’)
print “For the year {0}, Easter will fall on {1} {2}”.format(year, months[month_day[0]-1],month_day[1])