How to resolve the algorithm Holidays related to Easter step by step in the bc programming language

Published on 12 May 2024 09:40 PM
#Bc

How to resolve the algorithm Holidays related to Easter step by step in the bc programming language

Table of Contents

Problem Statement

Calculate the dates of:

As an example, calculate for the first year of each century from; From the year 325 CE on,   Easter Sunday   has been defined as the first Sunday after the first full moon on or after the day of the March equinox. However, the actual astronomical values for the moments of the full moon and equinox are not used. Instead, approximations are used, the first one being that the equinox is assumed to fall on March 21st every year. The tracking of the moon phases is similarly done with relatively straightforward arithmetic (compared to the sort required for astronomical accuracy) which amounts to maintaining a lunisolar calendar in parallel to our standard purely-solar one. When Pope Gregory reformed the Catholic calendar in 1582 CE, the drifting of Easter with respect to the seasons was the driving motivation, and the rules for determining it (called the computus) were altered to correct that drift. Catholic nations adopted both the new calendar and the new computus right away, while Western Protestant nations adopted them more gradually over the next 350 years or so. Eventually, even nations dominated by the Eastern Orthodox church adopted a similar calendar reform (the Revised Julian calendar), so pretty much the whole world agrees on what day it is for civil purposes. But the Eastern churches never adopted the corresponding Easter rule changes; they still use the original Julian calendar and computus to determine the date of what is known in the West as "Orthodox Easter". Therefore, your output should indicate which computus was used to calculate the dates and, at least for historical dates where the calendar can't be assumed or is location-dependent, which calendar those dates are given in. You may find algorithms on the Computus Wikipedia page. Some of the results: In the year 400 CE, Easter Sunday was April 1st (in the contemporary Julian calendar), making Ascension Thursday May 10th and Pentecost May 20th. It is ahistorical to give a date so far back for either Trinity Sunday or Corpus Christi, neither of which were observed until centuries later, but they would have been May 27th and 31st. If you extend the modern civil calendar back that far, those days are instead assigned the subsequent dates: Easter on April 2nd, Ascension on May 11th, Pentecost on May 21st. Skipping forward to the year 2100 CE, assuming the rules don't change between now and then, the Western churches will observe Easter on March 28, Ascension Thursday May 6th, Pentecost May 16th, Trinity Sunday May 23rd and Corpus Christi May 27th. Heading East, the Orthodox rules place Easter on April 18 in the original Julian calendar; the corresponding civil date is May 2nd. That puts the Ascension on June 10th and Pentecost June 20th. Orthodox Trinity Sunday is the same day as Pentecost, but they observe All Saints' Sunday the following week, June 27th. Corpus Christi is a purely Catholic date that has no Orthodox version.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Holidays related to Easter step by step in the bc programming language

Source code in the bc programming language

scale = 0

/* Format d days after March 21. Assumes March, April, May or June. */
define format(d) {
	if (d > 80) {		print "     Jun ",  d - 71
	} else if (d > 71) { 	print "     Jun 0", d - 71
	} else if (d > 49) {	print "     May ",  d - 40
	} else if (d > 40) {	print "     May 0", d - 40
	} else if (d > 19) {	print "     Apr ",  d - 10
	} else if (d > 10) {	print "     Apr 0", d - 10
	} else {		print "     Mar ",  d + 21
	}
}

/*
 * For year n, print Easter and related holidays.
 * Assumes n >= 1, scale = 0.
 */
define easter(n) {
	auto a, b, d, e, j

	/*
	 * Calculate e = day of Easter, following the 1886 paper,
	 * Kalender-Formeln (Calendar Formulae) by Chr. Zeller.
	 *   http://www.merlyn.demon.co.uk/zel-1886.htm
	 *
	 * With bc, p % 7 gives the wrong result when p < 0. To give the
	 * correct result, this code uses "+ 6 * j" where one might have
	 * used "- j". This works because because 6 == -1 (mod 7).
	 */
	if (n < 1583) {
		/* Julian calendar (before October 1582) */
		b = (19 * (n % 19) + 15) % 30
		d = (b + n + n / 4) % 7
	} else {
		/* Gregorian calendar (after October 1582) */
		j = n / 100
		a = n % 19
		b = (19 * a + 15 + j - (8 * j + 13) / 25 - j / 4) % 30
		d = (b + n + n / 4 + 6 * j + j / 4 + 2) % 7
		if (d == 0 && (b == 29 || (b == 28 && a > 10))) d = 7
	}
	e = b + 7 - d		/* This counts days after 21 March. */

	if(n < 1000) " "
	print n
	z = format(e)		/* Easter */
	z = format(e + 39)	/* Ascension Thursday */
	z = format(e + 49)	/* Pentecost */
	z = format(e + 56)	/* Trinity Sunday */
	z = format(e + 60)	/* Corpus Christi */
	print "\n"
}

print "         Easter     Ascension             Trinity    Corpus\n"
print "  AD     Sunday     Thursday   Pentecost  Sunday     Christi\n"
for (year =  400; year <= 2000; year += 100) z = easter(year)
for (year = 2010; year <= 2020; year +=   1) z = easter(year)
z = easter(2100)
quit


scale = 0

/* Format d days after March 21. Assumes March, April, May or June. */
define format(d) {
	if (d > 80) {		print "     Jun ",  d - 71
	} else if (d > 71) { 	print "     Jun 0", d - 71
	} else if (d > 49) {	print "     May ",  d - 40
	} else if (d > 40) {	print "     May 0", d - 40
	} else if (d > 19) {	print "     Apr ",  d - 10
	} else if (d > 10) {	print "     Apr 0", d - 10
	} else {		print "     Mar ",  d + 21
	}
}

/*
 * For year n, print Easter and related holidays.
 * Assumes n >= 1, scale = 0.
 */
define easter(n) {
	auto a, b, d, e, j

	/*
	 * Calculate e = day of Easter, following the 1886 paper,
	 * Kalender-Formeln (Calendar Formulae) by Chr. Zeller.
	 *   http://www.merlyn.demon.co.uk/zel-1886.htm
	 */
	b = (19 * (n % 19) + 15) % 30
	d = (b + n + n / 4) % 7
	e = b + 7 - d		/* This counts days after 21 March. */

	/*
	 * Starting at 1924 March 10 (Julian) / March 23 (Gregorian),
	 * change to the Gregorian calendar. Easter 1924 is April 27,
	 * after this change.
	 */
	if (n >= 1924) {
		/* This formula only works from March to December. */
		e += n / 100 - n / 400 - 2
	}

	if(n < 1000) " "
	print n
	z = format(e)		/* Easter */
	z = format(e + 39)	/* Ascension Thursday */
	z = format(e + 49)	/* Pentecost */
	z = format(e + 56)	/* All Saints' Sunday */
	print "\n"
}

print "         Easter     Ascension             All\n"
print "  AD     Sunday     Thursday   Pentecost  Saints\n"
for (year =  400; year <= 2000; year += 100) z = easter(year)
for (year = 2010; year <= 2020; year +=   1) z = easter(year)
z = easter(2100)
quit


  

You may also check:How to resolve the algorithm Comments step by step in the Isabelle programming language
You may also check:How to resolve the algorithm Integer overflow step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the CLU programming language
You may also check:How to resolve the algorithm SQL-based authentication step by step in the Ruby programming language