Friday, 22 April 2011

Computus is the algorithm used to calculate the date of Easter. Easter Sunday falls on the first Sunday after the full moon following the Spring equinox. For the purpose of the calculation the full moon is defined as day 14 of the lunar month and the Spring equinox as 20th March.

Unfortunately Computus defies any attempt to render it with beautiful code! This C function roughly follows the assembly language so is a little uglier than strictly necessary:

The algorithm is similar to MaybeGauss1 found in J R Stockton's collection of algorithms for Easter Sunday and is valid for the Gregorian calendar well into the fourth millenium. The algorithm can be adapted to calculate a number of other dates:

Shrove Tuesday - 47 days before Easter Sunday

First Sunday in Lent - 42 days before

Palm Sunday - 7 days before

Whit Sunday - 49 days after

Finally here's the same algorithm in 8086 assembly language, length 128 bytes. On entry, AX is the year. On exit AL is the day, AH is the month:

I think you did a pretty good job of making it pretty in C. I think the only thing you could to to improve readability would split some of those up onto multiple lines but that would be wasteful. Good job all around.

Greetings! for posting such a useful blog. Your weblog is not only informative and also very artistic too. There usually are extremely couple of people who can write not so easy articles that creatively. Keep up the good work !