Skip to content

Commit

Permalink
'easter.cpp' : Maik Meyer and Gary Kronk pointed out that the algorit…
Browse files Browse the repository at this point in the history
…hm used here is for the Gregorian calendar, and produces misleading results for years before 1583.
  • Loading branch information
Bill-Gray committed Jun 13, 2024
1 parent 96c39b0 commit 8224572
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions easter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Unlike the formula given by Gauss, this method has no exception and
is valid for all years in the Gregorian calendar, hence from 1583 on."
I modified the method to include negative years by taking advantage
of the fact that, in the Gregorian calendar, Easter recurs on a 5.7
million year cycle. Add 5.7 million to the year, and all numbers are
positive (as long as year > -5700000, of course! I suppose one could
add, say, 570 million instead, extending the range to cover roughly
the Paleozoic era to a time 1.5 billion years hence...)
Note that this formula results from the Gregorian calendar change.
Before 1583, different rules were used to determine the date of Easter.
You can use the formula for dates before 1583, but the results will
not match the dates when Easter was actually observed.
The relevant pages from _General Astronomy_ can be found at
https://archive.org/details/generalastronomy0000hspe/page/72/mode/2up
The test program can be run with zero, one, or two command line
arguments, to get three very different types of output.
If run without command-line arguments, the program computes the day
of Easter over an entire 5.7 million year cycle. That lets it show the
frequency on which Easter occurs on a given day; the result looks like
Easter repeats over a cycle of 5.7 million years. If run without
command-line arguments, this program computes the day of Easter over an
entire cycle. That lets it show the frequency on which Easter occurs on
a given day; the result looks like
Mar 22: 0.48333 = 29/60 Apr 3: 3.38333 = 203/60 Apr 15: 3.38333 = 203/60
Mar 23: 0.95000 = 19/20 Apr 4: 3.26666 = 49/15 Apr 16: 3.26666 = 49/15
Expand Down Expand Up @@ -74,23 +77,20 @@ Easter for a 75-year time span. For example, 'easter 2010' gives
2024 Mar 31 2039 Apr 10 2054 Mar 29 2069 Apr 14 2084 Mar 26
Run with two command line arguments of a month (3=March or 4=April) and
a day, one gets a list of years from 0 AD to 10000 AD when Easter would
a day, one gets a list of years from 1583 AD to 10000 AD when Easter would
fall on that day. For example, 'easter 3 22' would give the following
list of years when Easter fell on 22 March, the earliest day possible:
15 387 482 539 607 854 1074 1131 1226 1503 1598 1693 1761 1818 2285
2353 2437 2505 2972 3029 3401 3496 3564 3648 3716 4308 5299 5671 6043 6195
6263 6415 6635 6703 6798 6882 6950 7322 7474 7542 7637 7789 7914 8161 8533
8685 8753 8848 8905 9125 9220 9372 9440 9812 9964
55 found over 10000 years
*/
1598 1693 1761 1818 2285 2353 2437 2505 2972 3029 3401 3496 3564 3648 3716
4308 5299 5671 6043 6195 6263 6415 6635 6703 6798 6882 6950 7322 7474 7542
7637 7789 7914 8161 8533 8685 8753 8848 8905 9125 9220 9372 9440 9812 9964
void easter_date( const long year, int *month, int *day);
45 found over 8417 years
*/

void easter_date( const long year, int *month, int *day)
{
const long year2 = year + 5700000L;
const long a = year2 % 19L, b = year2 / 100L, c = year2 % 100L;
const long a = year % 19L, b = year / 100L, c = year % 100L;
const long d = b / 4L, e = b % 4L, f = (b + 8L) / 25L;
const long g = (b - f + 1L) / 3L, h = (19L * a + b - d - g + 15L) % 30L;
const long i = c / 4L, k = c % 4L, l = (32L + e + e + i + i - h - k) % 7L;
Expand Down Expand Up @@ -145,7 +145,7 @@ int main( int argc, char **argv)
{
int n_found = 0;

for( year = 0; year < 10000; year++)
for( year = 1583; year < 10000; year++)
{
easter_date( year, &month, &day);
if( month == atoi( argv[1]) && day == atoi( argv[2]))
Expand All @@ -155,7 +155,7 @@ int main( int argc, char **argv)
printf( "\n");
}
}
printf( "\n%d found over 10000 years\n", n_found);
printf( "\n%d found over 8417 years\n", n_found);
}
else
{
Expand Down Expand Up @@ -207,7 +207,7 @@ int main( int argc, char **argv)
printf( "\nRun 'easter' with a year on the command line to get the date\n");
printf( "of Easter for that year. For example, 'easter 2008' will\n");
printf( "get the output 'March 23'. Alternatively, give a month and\n");
printf( "day on the command line to get the years between 0 and 10000\n");
printf( "day on the command line to get the years between 1583 and 10000\n");
printf( "when Easter will fall on that day. For example, 'easter 3 23'\n");
printf( "will produce a list of all years when Easter is on 23 March.\n");
printf( "\nNote that Easter cannot occur before 22 March or after 25 April.\n");
Expand Down

0 comments on commit 8224572

Please sign in to comment.