Skip to content

Commit 0f3cf98

Browse files
committed
Merge branch 'master' of https://github.com/Trashtalk217/algorithm-archive into aaa-py-4
2 parents cc548a3 + 46231cf commit 0f3cf98

File tree

4 files changed

+141
-19
lines changed

4 files changed

+141
-19
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
defcomputus(year, servois =false)
2+
# Year's position on the 19 year metonic cycle
3+
a = year %19
4+
5+
# Century index
6+
k = year //100
7+
8+
# Shift of metonic cycle, add a day offset every 300 years
9+
p= (13+8* k) //25
10+
11+
# Correction for non-observed leap days
12+
q = k //4
13+
14+
# Correction to starting point of calculation each century
15+
m = (15-p+ k - q) %30
16+
17+
# Number of days from March 21st until the full moon
18+
d = (19* a + m) %30
19+
20+
# Returning if user wants value for Servois' table
21+
if servois
22+
return (21+ d) %31
23+
end
24+
25+
# Finding the next Sunday
26+
# Century-based offset in weekly calculation
27+
n = (4+ k - q) %7
28+
29+
# Correction for leap days
30+
b = year %4
31+
c = year %7
32+
33+
# Days from d to next Sunday
34+
e = (2* b +4* c +6* d + n) %7
35+
36+
# Historical corrections for April 26 and 25
37+
if (d ==29&& e ==6) || (d ==28&& e ==6&& a >10)
38+
e =-1
39+
end
40+
41+
# Determination of the correct month for Easter
42+
if (22+ d + e >31)
43+
return"April "+ (d + e -9).to_s
44+
else
45+
return"March "+ (22+ d + e).to_s
46+
end
47+
end
48+
49+
# Here, we will output the date of the Paschal full moon
50+
# (using Servois notation), and Easter for 2020-2030
51+
defmain
52+
a = (2020..2030).to_a
53+
servois_numbers = a.map{|y| computus(y, servois =true) }
54+
easter_dates = a.map{|y| computus(y) }
55+
56+
puts"The following are the dates of the Paschal full moon (using Servois "+
57+
"notation) and the date of Easter for 2020-2030 AD:"
58+
puts"Year\tServois number\tEaster"
59+
a.each_index{|i|
60+
puts"#{a[i]}\t#{servois_numbers[i]}\t\t\t\t#{easter_dates[i]}"
61+
}
62+
end
63+
64+
main
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defcomputus(year, servois=False):
2+
# Year's position on the 19-year metonic cycle
3+
a=year%19
4+
5+
# Century index
6+
k=year//100
7+
8+
# Shift of metonic cycle, add a day offset every 300 years
9+
p= (13+8*k) //25
10+
11+
# Correction for non-observed leap days
12+
q=k//4
13+
14+
# Correction to starting point of calculation each century
15+
M= (15-p+k-q) %30
16+
17+
# Number of days from March 21st until the full moon
18+
d= (19*a+M) %30
19+
20+
# Returning if user wants value for Servois' table
21+
ifservois:
22+
return (21+d) %31
23+
24+
# Finding the next Sunday
25+
# Century-based offset in weekly calculation
26+
N= (4+k-q) %7
27+
28+
# Correction for leap days
29+
b=year%4
30+
c=year%7
31+
32+
# Days from d to next Sunday
33+
e= (2*b+4*c+6*d+N) %7
34+
35+
# Historical corrections for April 26 and 25
36+
if (d==29ande==6) or (d==28ande==6anda>10):
37+
e=-1
38+
39+
# Determination of the correct month for Easter
40+
if22+d+e>31:
41+
return"April "+str(d+e-9)
42+
else:
43+
return"March "+str(22+d+e)
44+
45+
46+
# Here, we will output the date of the Paschal full moon
47+
# (using Servois notation), and Easter for 2020-2030
48+
49+
print(
50+
"The following are the dates of the Paschal full moon (using Servois",
51+
"notation) and the date of Easter for 2020-2030 AD:",
52+
)
53+
print("Year\tServois number\tEaster")
54+
foryearinrange(2020, 2031):
55+
print(f"{year}\t{computus(year, servois=True)}\t{computus(year)}")

‎contents/contents/computus/code/julia/gauss_easter.jl‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ function computus(year; servois=false)
22

33
# Year's position on the 19 year metonic cycle
44
a =mod(year, 19)
5-
5+
66
# Century index
7-
k =floor(Int, year/100)
7+
k =fld(year, 100)
88

99
# Shift of metonic cycle, add a day offset every 300 years
10-
p =floor(Int, (13+8* k) /25)
10+
p =fld(13+8* k, 25)
1111

1212
# Correction for non-observed leap days
13-
q =floor(Int, k /4)
13+
q =fld(k,4)
1414

1515
# Correction to starting point of calculation each century
1616
M =mod(15- p + k - q, 30)
@@ -20,7 +20,7 @@ function computus(year; servois=false)
2020

2121
# Returning if user wants value for Servois' table
2222
if servois
23-
returnmod(21+d,31)
23+
returnmod(21+d,31)
2424
end
2525

2626
# Finding the next Sunday
@@ -40,24 +40,23 @@ function computus(year; servois=false)
4040
end
4141

4242
# Determination of the correct month for Easter
43-
if(22+ d + e >31)
44-
return"April "*string(d + e -9)
43+
if(22+ d + e >31)
44+
return"April "*string(d + e -9)
4545
else
46-
return"March "*string(22+d+e)
46+
return"March "*string(22+ d +e)
4747
end
4848
end
4949

5050
# Here, we will output the date of the Paschal full moon
5151
# (using Servois notation), and Easter for 2020-2030
5252

53-
a =[i for i =2020:2030]
54-
servois_numbers =computus.(a;servois=true)
53+
a =collect(2020:2030)
54+
servois_numbers =computus.(a;servois=true)
5555
easter_dates =computus.(a)
5656

57-
println("The following are the dates of the Paschal full moon (using Servois "*
57+
println("The following are the dates of the Paschal full moon (using Servois "*
5858
"notation) and the date of Easter for 2020-2030 AD:")
59-
println("Year Servois number Easter")
59+
println("Year\tServois number\tEaster")
6060
for i =1:length(a)
61-
println(string(a[i])*"\t"*string(servois_numbers[i])*"\t\t"*
62-
string(easter_dates[i]))
61+
println("$(a[i])\t$(servois_numbers[i])\t\t\t\t$(easter_dates[i])")
6362
end

‎contents/contents/computus/computus.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ As an example, look at the following table
205205

206206
| January 1st | Day of the week | Special considerations |
207207
| ----------- | --------------- | ---------------------- |
208-
| 2017 | Sunday |None |
209-
| 2018 | Monday |None |
210-
| 2019 | Tuesday |None |
211-
| 2020 | Wednesday |Leap Year |
212-
| 2021 | Friday |None |
208+
| 2017 | Sunday | None|
209+
| 2018 | Monday | None|
210+
| 2019 | Tuesday | None|
211+
| 2020 | Wednesday | Leap Year|
212+
| 2021 | Friday | None|
213213

214214
Simply put, every year we should subtract one day of the week, but on leap years, we should subtract 2.
215215
To keep tabs on this, we need two separate counts,
@@ -281,6 +281,10 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
281281
{% method %}
282282
{% sample lang="jl" %}
283283
[import, lang:"julia"](code/julia/gauss_easter.jl)
284+
{% sample lang="py" %}
285+
[import, lang:"python"](code/python/gauss_easter.py)
286+
{% sample lang="crystal" %}
287+
[import, lang:"crystal"](code/crystal/gauss_easter.cr)
284288
{% endmethod %}
285289

286290

0 commit comments

Comments
(0)