Sunday, April 4, 2010

Easter

In honor of the day, I present the following short program for calculating the date of Easter. The method is from Butcher's Ecclesiastical Calendar (1876). I present it in the form given in Peter Duffett-Smith's Practical Astronomy With Your Calculator (Cambridge 1981, the 1988 version is still available from Amazon, et al).

Numerous implementations of this algorithm in various other languages (including C#), as well as historical details, etc., can easily be found via web search if you're interested.

By the way, Mr. Duffett-Smith's book (and I presume his later books on computer astronomy) is an absolute gem. If you've ever read predictions of eclipses, etc. and wondered "how did they calculate that?" his books will make all such mysteries plain.

(Presented “as-is” and without warranty or implied fitness; use at your own risk.)
// Computes the date of Easter for a
// given year beginning from 1583.
// Method is that described in "Butcher's
// Ecclesiastical Calendar" (1876),
// and as given in:
// "Practical Astronomy With Your Calculator"
// by Peter Duffett-Smith (Cambridge, 1981).
let easter year =
// Return integer and fractional
// part of a division as a tuple.
let (/%) l r = (l/r),(l%r)
// The calculation.
let a = year%19
let (b,c) = year/%100
let (d,e) = b/%4
let f = (b+8)/25
let g = (b-f+1)/3
let h = (19*a+b-d-g+15)%30
let (i,k) = c/%4
let l = (32+2*e+2*i-h-k)%7
let m = (a+11*h+22*l)/451
let (n,p) = (h+l+7*m+114)/%31
new System.DateTime(year,n,p+1)

let e2009 = easter 2009
let e2010 = easter 2010
let e2011 = easter 2011

printfn
"Easter this year is: %s"
((easter System.DateTime.Now.Year).ToString())

System.Console.ReadLine() |> ignore

No comments: