Posts Tagged calendar

Easter Fun!

So — on what date does Easter fall? Now YOU can impress your friends by using either of the Perl scripts below… Thanks to this site which supplied both Butcher’s and Oudin’s algorithm:

Butcher’s Algorithm in Perl (1876 — and the Perl code is almost that old too! 🙂 )

sub GetEasterDate {
my($year)=@_;
my $a=$year%19;
my $b=int($year/100);
my $c=$year%100;
my $d=int($b/4);
my $e=$b%4;
my $f=int(($b+8)/25);
my $g=int(($b-$f+1)/3);
my $h=(19*$a+$b-$d-$g+15)%30;
my $i=int($c/4);
my $k=$c%4;
my $l=(32+2*$e+2*$i-$h-$k)%7;
my $m=int(($a+11*$h+22*$l)/451);
my $month=int(($h+$l-7*$m+114)/31);
my $p=($h+$l-7*$m+114)%31;
my $day=$p+1;
return($month."/".$day."/".$year."\n");
};

Oudin’s Method in Perl (1940)

sub GetEasterDate {
my($year)=@_;
my $century = int($year / 100);
my $G = $year % 19;
my $K = int(($century - 17) / 25);
my $I = ($century - int($century / 4) - int(($century - $K) / 3) + 19 * $G + 15) % 30;
my $I = $I - (int($I / 28)) * (1 - int($I / 28) * int(29 / ($I + 1)) * int((21 - $G) / 11));
my $J = ($year + int($year / 4) + $I + 2 - $century + int($century / 4)) % 7;
my $L = $I - $J;
my $month = 3 + int(($L + 40) / 44);
my $day = $L + 28 - 31 * int($month / 4);
return($month."/".$day."/".$year."\n");
};

The second algorithm is more efficient. If I run 100,000 years of calculations I get about .035ms better performance over the “older” method.

For those of us who just “want the facts”, here you go:

  • 4/12/2009
  • 4/4/2010
  • 4/24/2011
  • 4/8/2012
  • 3/31/2013
  • 4/20/2014
  • 4/5/2015
  • 3/27/2016
  • 4/16/2017
  • 4/1/2018
  • 4/21/2019
  • 4/12/2020
  • 4/4/2021
  • 4/17/2022
  • 4/9/2023
  • 3/31/2024
  • 4/20/2025
  • 4/5/2026
  • 3/28/2027
  • 4/16/2028
  • 4/1/2029
  • 4/21/2030
  • 4/13/2031
  • 3/28/2032
  • 4/17/2033
  • 4/9/2034
  • 3/25/2035
  • 4/13/2036
  • 4/5/2037
  • 4/25/2038
  • 4/10/2039
  • 4/1/2040
  • 4/21/2041
  • 4/6/2042
  • 3/29/2043
  • 4/17/2044
  • 4/9/2045
  • 3/25/2046
  • 4/14/2047
  • 4/5/2048
  • 4/18/2049

Oh, and if you’re looking for a pattern, there is one: Every 5,700,000 years.

Thanks to yesterday’s Slashdot post for getting me interested in this.

, , , , ,

3 Comments