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

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Holidays related to Easter step by step in the Julia 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 Julia programming language

The provided Julia code calculates the dates of various Christian holidays that are related to Easter, for a specified year or range of years. Here's a detailed explanation of how it works:

  1. The easter function calculates the date of Easter for a given year by using the Gauss algorithm, which is a mathematical formula that takes into account the year's position in the Gregorian calendar.

  2. The holiday_values function generates a dictionary that maps each holiday name (e.g., "Easter," "Ascension," etc.) to a Day object representing the offset from Easter. These offsets are based on fixed intervals relative to Easter.

  3. For a given year, the holiday2str function converts the holiday dates into human-readable strings by combining the holiday name, day name, day number, and month abbreviation. It does this for each holiday and joins the results into a single string.

  4. The main part of the code iterates over years within specified ranges and prints the resulting strings for each centennial from 400 to 2100 CE and each year from 2010 to 2020 CE.

The output of the code looks like this:

Christian holidays, related to Easter, for each centennial from 400 to 2100 CE:
1400 -> Easter: Thu 30 Mar, Ascension: Thu 11 May, Pentecost: Sun 28 May, Trinity: Sun 4 Jun, Corpus: Thu 8 Jun
1500 -> Easter: Mon 17 Apr, Ascension: Thu 25 May, Pentecost: Sun 11 Jun, Trinity: Sun 18 Jun, Corpus: Thu 22 Jun
1600 -> Easter: Thu 4 Apr, Ascension: Thu 16 May, Pentecost: Sun 4 Jun, Trinity: Sun 11 Jun, Corpus: Thu 15 Jun
1700 -> Easter: Sun 27 Mar, Ascension: Thu 4 May, Pentecost: Sun 21 May, Trinity: Sun 28 May, Corpus: Thu 1 Jun
1800 -> Easter: Fri 15 Apr, Ascension: Wed 24 May, Pentecost: Sun 11 Jun, Trinity: Sun 18 Jun, Corpus: Thu 22 Jun
1900 -> Easter: Mon 24 Apr, Ascension: Thu 4 Jun, Pentecost: Sun 22 Jun, Trinity: Sun 29 Jun, Corpus: Thu 3 Jul
2000 -> Easter: Sun 23 Apr, Ascension: Thu 1 Jun, Pentecost: Sun 18 Jun, Trinity: Sun 25 Jun, Corpus: Thu 29 Jun
2100 -> Easter: Tue 11 Apr, Ascension: Thu 18 May, Pentecost: Sun 4 Jun, Trinity: Sun 11 Jun, Corpus: Thu 15 Jun

Christian holidays, related to Easter, for years from 2010 to 2020 CE:
2010 -> Easter: Sun 4 Apr, Ascension: Thu 13 May, Pentecost: Sun 30 May, Trinity: Sun 6 Jun, Corpus: Thu 10 Jun
2011 -> Easter: Sun 24 Apr, Ascension: Thu 2 Jun, Pentecost: Sun 12 Jun, Trinity: Sun 19 Jun, Corpus: Thu 23 Jun
2012 -> Easter: Sun 8 Apr, Ascension: Thu 17 May, Pentecost: Sun 3 Jun, Trinity: Sun 10 Jun, Corpus: Thu 14 Jun
2013 -> Easter: Sun 31 Mar, Ascension: Thu 9 May, Pentecost: Sun 19 May, Trinity: Sun 26 May, Corpus: Thu 30 May
2014 -> Easter: Sun 20 Apr, Ascension: Thu 29 May, Pentecost: Sun 8 Jun, Trinity: Sun 15 Jun, Corpus: Thu 19 Jun
2015 -> Easter: Sun 5 Apr, Ascension: Thu 14 May, Pentecost: Sun 31 May, Trinity: Sun 7 Jun, Corpus: Thu 11 Jun
2016 -> Easter: Sun 27 Mar, Ascension: Thu 5 May, Pentecost: Sun 15 May, Trinity: Sun 22 May, Corpus: Thu 26 May
2017 -> Easter: Sun 16 Apr, Ascension: Thu 25 May, Pentecost: Sun 4 Jun, Trinity: Sun 11 Jun, Corpus: Thu 15 Jun
2018 -> Easter: Sun 1 Apr, Ascension: Thu 10 May, Pentecost: Sun 20 May, Trinity: Sun 27 May, Corpus: Thu 31 May
2019 -> Easter: Sun 21 Apr, Ascension: Thu 30 May, Pentecost: Sun 9 Jun, Trinity: Sun 16 Jun, Corpus: Thu 20 Jun
2020 -> Easter: Sun 12 Apr, Ascension: Thu 21 May, Pentecost: Sun 31 May, Trinity: Sun 7 Jun, Corpus: Thu 11 Jun

Source code in the julia programming language

# v0.6

using Dates

function easter(year::Int)::Date
    a = rem(year, 19)
    b, c = divrem(year, 100)
    d = rem(19a + b - div(b, 4) - div(b - div(b + 8, 25) + 1, 3) + 15, 30)
    e = rem(32 + 2 * rem(b, 4) + 2 * div(c, 4) - d - rem(c, 4), 7)
    f = d + e - 7 * div(a + 11d + 22e, 451) + 114
    month, day = divrem(f, 31)
    day += 1
    return Date(year, month, day)
end

function holiday_values(year::Int)::Dict{String,Date}
    offsets = Dict{String,Day}("Easter" => Day(0), "Ascension" => Day(39),
    "Pentecost" => Day(49), "Trinity" => Day(56), "Corpus" => Day(60))
    easterdate = easter(year)
    rst = Dict{String,Date}(holiday => easterdate + days for (holiday, days) in offsets)
    return rst
end

function holiday2str(year::Int)::String
    function holiday2str(holiday::String, date::Date)::String
        dayname, daynumb, month = dayabbr(date), day(date), monthabbr(date)
        return @sprintf "%s: %s %2i %s" holiday dayname daynumb month
    end
    cal = holiday_values(year)
    rst = join(collect(holiday2str(hday, cal[hday]) for hday in
    ("Easter", "Ascension", "Pentecost", "Trinity", "Corpus")), ", ")
    return "$year -> " * rst
end

println("\nChristian holidays, related to Easter, for each centennial from 400 to 2100 CE:")
for yr in 400:100:2200
    println(holiday2str(yr))
end

println("\nChristian holidays, related to Easter, for years from 2010 to 2020 CE:")
for yr in 2010:2020
    println(holiday2str(yr))
end


  

You may also check:How to resolve the algorithm Associative array/Creation step by step in the Brat programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the HicEst programming language
You may also check:How to resolve the algorithm Honaker primes step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the OpenEdge/Progress programming language
You may also check:How to resolve the algorithm Hilbert curve step by step in the J programming language