Skip to content

Commit 0373d8e

Browse files
authored
Adding computus in C (#697)
* Editting computus.md * Adding gauss_easter.c
1 parent 92e7ae5 commit 0373d8e

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <stdio.h>
2+
3+
char *computus(int year, int servois, char *out, size_t out_size) {
4+
// Year's position on the 19 year metonic cycle
5+
int a = year % 19;
6+
7+
// Century index
8+
int k = year / 100;
9+
10+
//Shift of metonic cycle, add a day offset every 300 years
11+
int p = (13 + 8 * k) / 25;
12+
13+
// Correction for non-observed leap days
14+
int q = k / 4;
15+
16+
// Correction to starting point of calculation each century
17+
int M = (15 - p + k - q) % 30;
18+
19+
// Number of days from March 21st until the full moon
20+
int d = (19 * a + M) % 30;
21+
22+
// Returning if user wants value for Servois' table
23+
if (servois) {
24+
snprintf(out, out_size, "%d",(21 + d) % 31);
25+
return out;
26+
}
27+
28+
// Finding the next Sunday
29+
// Century-based offset in weekly calculation
30+
int N = (4 + k - q) % 7;
31+
32+
// Correction for leap days
33+
int b = year % 4;
34+
int c = year % 7;
35+
36+
// Days from d to next Sunday
37+
int e = (2 * b + 4 * c + 6 * d + N) % 7;
38+
39+
// Historical corrections for April 26 and 25
40+
if ((d == 29 && e == 6) || (d == 28 && e == 6 && a > 10)) {
41+
e = -1;
42+
}
43+
44+
if ((22 + d + e) > 31) {
45+
snprintf(out, out_size, "April %d", d + e - 9);
46+
} else {
47+
snprintf(out, out_size, "March %d", 22 + d + e);
48+
}
49+
50+
return out;
51+
}
52+
53+
int main() {
54+
char tmp1[9], tmp2[9];
55+
56+
printf("The following are the dates of the Paschal full moon (using "
57+
"Servois notation) and the date of Easter for 2020-2030 AD:\n");
58+
59+
printf("Year\tServois number\tEaster\n");
60+
61+
for (int year = 2020; year <= 2030; year++) {
62+
printf("%d\t\t%s\t%s\n", year, computus(year, 1, tmp1, 9),
63+
computus(year, 0, tmp2, 9));
64+
}
65+
66+
return 0;
67+
}
68+

contents/computus/computus.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ $$
131131
k = \left\lfloor\frac{\text{year}}{100}\right\rfloor,
132132
$$
133133
where $$\lfloor\cdot\rfloor$$ is a flooring operation of rounding the value down to the nearest integer.
134-
With this, we can calculate the shift in the Metonic cycle to be,
134+
With this, we can calculate the shift in the Metonic cycle to be,
135135

136136
$$
137137
p = \left\lfloor\frac{13+8k}{25}\right\rfloor.
@@ -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="c" %}
289+
[import, lang:"c"](code/c/gauss_easter.c)
288290
{% endmethod %}
289291

290292

0 commit comments

Comments
 (0)