This Observer is pleased to express appreciation for your observation of this blog.


23 March 2008

Homage to Computus

For those observing per the Gregorian calendar, today is Easter Sunday. The method (Computus) used to determine that fact is complex, and has been cited as a primary motivation for keeping arithmetic alive through the Western Middle Ages. In acknowledgment of the importance of arithmetic's persistence today, and given the convenient availability of an algorithmic description, TO chose to undertake the simple programming exercise of implementing the method, and attaches the C code as a comment.

1 comment:

This Observer said...

// Easter date computation (Computus), per Gauss' algorithm
// description at http://en.wikipedia.org/wiki/Easter_date
// as of 23 March (Gregorian Easter) 2008

// #includes of stdio.h and stdlib.h are needed to compile, but are disallowed as tags in blogger comments

main(int argc, char **argv)
{
int year, a, b, c, d, e, m, n, edate;

if (argc < 2)
{
printf("Computus asks... please enter year as command line argument\n");
exit(0);
}

year=atoi(argv[1]);

if (year >= 1583 && year <=1699)
{
m = 22; n= 2;
}
else if (year >=1700 && year <=1799)
{
m = 23; n = 3;
}
else if (year >=1800 && year <=1899)
{
m = 23; n = 4;
}
else if (year >=1900 && year <=2099)
{
m = 24; n = 5;
}
else if (year >=2100 && year <=2199)
{
m = 24; n = 6;
}
else if (year >=2200 && year <=2299)
{
m = 25; n = 0;
}
else
{
printf("Computus speaks... year %d is out of my range, sorry.\n", year);
exit(0);
}

a = year % 19;
b = year % 4;
c = year % 7;

// derive d and e for Gregorian calendar

d = ((19*a) + m) % 30;
e = ((2*b) + (4*c) + (6*d) + n) % 7;

if ((d+e) < 10)
{ // then Easter is in March
printf("Computus speaks... the Gregorian Easter date for %d is %d March\n", year, (int) d+e+22);
}
else
{ // then Easter is in April
edate=(d+e)-9;
if (edate==26) edate = 19;
if (edate==25 && d==28 && e==6 && a>10) edate = 18;
printf("Computus speaks... the Gregorian Easter date for %d is %d April\n", year, edate);
}
}