Skip to content

Commit 370f717

Browse files
dovisutuleios
andauthored
Add Gauss_Easter in Powershell (algorithm-archivists#684)
Co-authored-by: James Schloss <[email protected]>
1 parent 9315ce9 commit 370f717

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function Calculate-Computus([int]$Year, [switch]$Servois) {
2+
3+
# Year's position on the 19 year metonic cycle
4+
$a = $Year % 19
5+
6+
# Century index
7+
$k = [Math]::Floor($Year / 100)
8+
9+
# Shift of metonic cycle, add a day offset every 300 years
10+
$p = [Math]::Floor((13 + 8 * $k) / 25)
11+
12+
# Correction for non-observed leap days
13+
$q = [Math]::Floor($k / 4)
14+
15+
# Correction to starting point of calculation each century
16+
$M = (15 - $p + $k - $q) % 30
17+
18+
# Number of days from March 21st until the full moon
19+
$d = (19 * $a + $M) % 30
20+
21+
# Returning if user wants value for Servois' table
22+
if($Servois) {
23+
return ((21 + $d) % 31).ToString()
24+
}
25+
26+
# Finding the next Sunday
27+
# Century-based offset in weekly calculation
28+
$N = (4 + $k - $q) % 7
29+
30+
# Correction for leap days
31+
$b = $Year % 4
32+
$c = $Year % 7
33+
34+
# Days from d to next Sunday
35+
$e = (2 * $b + 4 * $c + 6 * $d + $N) % 7
36+
37+
# Historical corrections for April 26 and 25
38+
if(($d -eq 29 -and $e -eq 6) -or ($d -eq 28 -and $e -eq 6 -and $a -gt 10)) {
39+
$e = -1
40+
}
41+
42+
# Determination of the correct month for Easter
43+
if(22 + $d + $e -gt 31) {
44+
return "April " + ($d + $e - 9)
45+
}
46+
else {
47+
return "March " + (22 + $d + $e)
48+
}
49+
}
50+
51+
52+
# Here, we will output the date of the Paschal full moon
53+
# (using Servois notation), and Easter for 2020-2030
54+
55+
Write-Host "The following are the dates of the Paschal full moon (using Servois",
56+
"notation) and the date of Easter for 2020-2030 AD:"
57+
Write-Host "Year`tServois number`tEaster"
58+
foreach($year in 2020..2030) {
59+
Write-Host "$year`t$(Calculate-Computus $year -Servois)`t`t$(Calculate-Computus $year)"
60+
}

contents/computus/computus.md

+2
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
285285
[import, lang:"python"](code/python/gauss_easter.py)
286286
{% sample lang="crystal" %}
287287
[import, lang:"crystal"](code/crystal/gauss_easter.cr)
288+
{% sample lang="ps1" %}
289+
[import, lang:"powershell"](code/powershell/gauss_easter.ps1)
288290
{% sample lang="c" %}
289291
[import, lang:"c"](code/c/gauss_easter.c)
290292
{% sample lang="cpp" %}

0 commit comments

Comments
 (0)