From cd2750322e556d7ac3c5cc7ba7bf74b822975773 Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Fri, 15 May 2020 18:21:24 +0100 Subject: [PATCH 1/2] Editting computus.md --- contents/computus/computus.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contents/computus/computus.md b/contents/computus/computus.md index cd3c3b678..429fe3a54 100644 --- a/contents/computus/computus.md +++ b/contents/computus/computus.md @@ -131,7 +131,7 @@ $$ k = \left\lfloor\frac{\text{year}}{100}\right\rfloor, $$ where $$\lfloor\cdot\rfloor$$ is a flooring operation of rounding the value down to the nearest integer. -With this, we can calculate the shift in the Metonic cycle to be, +With this, we can calculate the shift in the Metonic cycle to be, $$ 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 [import, lang:"python"](code/python/gauss_easter.py) {% sample lang="crystal" %} [import, lang:"crystal"](code/crystal/gauss_easter.cr) +{% sample lang="c" %} +[import, lang:"c"](code/c/gauss_easter.c) {% endmethod %} From cc6beb84a35b7ef33983988e32f89c2897642dc2 Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Fri, 15 May 2020 18:22:26 +0100 Subject: [PATCH 2/2] Adding gauss_easter.c --- contents/computus/code/c/gauss_easter.c | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 contents/computus/code/c/gauss_easter.c diff --git a/contents/computus/code/c/gauss_easter.c b/contents/computus/code/c/gauss_easter.c new file mode 100644 index 000000000..e168179a2 --- /dev/null +++ b/contents/computus/code/c/gauss_easter.c @@ -0,0 +1,68 @@ +#include + +char *computus(int year, int servois, char *out, size_t out_size) { + // Year's position on the 19 year metonic cycle + int a = year % 19; + + // Century index + int k = year / 100; + + //Shift of metonic cycle, add a day offset every 300 years + int p = (13 + 8 * k) / 25; + + // Correction for non-observed leap days + int q = k / 4; + + // Correction to starting point of calculation each century + int M = (15 - p + k - q) % 30; + + // Number of days from March 21st until the full moon + int d = (19 * a + M) % 30; + + // Returning if user wants value for Servois' table + if (servois) { + snprintf(out, out_size, "%d",(21 + d) % 31); + return out; + } + + // Finding the next Sunday + // Century-based offset in weekly calculation + int N = (4 + k - q) % 7; + + // Correction for leap days + int b = year % 4; + int c = year % 7; + + // Days from d to next Sunday + int e = (2 * b + 4 * c + 6 * d + N) % 7; + + // Historical corrections for April 26 and 25 + if ((d == 29 && e == 6) || (d == 28 && e == 6 && a > 10)) { + e = -1; + } + + if ((22 + d + e) > 31) { + snprintf(out, out_size, "April %d", d + e - 9); + } else { + snprintf(out, out_size, "March %d", 22 + d + e); + } + + return out; +} + +int main() { + char tmp1[9], tmp2[9]; + + printf("The following are the dates of the Paschal full moon (using " + "Servois notation) and the date of Easter for 2020-2030 AD:\n"); + + printf("Year\tServois number\tEaster\n"); + + for (int year = 2020; year <= 2030; year++) { + printf("%d\t\t%s\t%s\n", year, computus(year, 1, tmp1, 9), + computus(year, 0, tmp2, 9)); + } + + return 0; +} +