diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6a5c86908..fb8ecde19 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -57,4 +57,5 @@ This file lists everyone, who contributed to this repo and wanted to show up her - Delphi1024 - ntindle - Mahdi Sarikhani -- Ridham177 \ No newline at end of file +- Ridham177 +- Hugo Salou diff --git a/book.json b/book.json index 63429dfa0..690acec87 100644 --- a/book.json +++ b/book.json @@ -193,8 +193,8 @@ { "lang": "ps1", "name": "PowerShell" - }, - { + }, + { "lang": "v", "name": "Vlang" }, @@ -217,6 +217,10 @@ { "lang": "coco", "name": "Coconut" + }, + { + "lang": "dart", + "name": "Dart" } ] } diff --git a/contents/computus/code/dart/gauss_easter.dart b/contents/computus/code/dart/gauss_easter.dart new file mode 100644 index 000000000..ab48aab20 --- /dev/null +++ b/contents/computus/code/dart/gauss_easter.dart @@ -0,0 +1,63 @@ +String computus(int year, {bool servois = false}) { + // Year's position in metonic cycle + final a = year % 19; + + // Century index + final k = (year / 100).floor(); + + // Shift of metonic cycle, add a day offset every 300 years + final p = ((13 + 8 * k) / 25).floor(); + + // Correction for non-observed leap days + final q = (k / 4).floor(); + + // Correction to starting point of calculation each century + final M = (15 - p + k - q) % 30; + + // Number of days from March 21st until the full moon + final d = (19 * a + M) % 30; + + // Returning if user wants value for Servois' table + if (servois) { + return ((21 + d) % 31).toString(); + } + + // Finding the next Sunday + // Century-based offset in weekly calculation + final N = (4 + k - q) % 7; + + // Correction for leap days + final b = year % 4; + final c = year % 7; + + // Days from d to next Sunday + var e = (2 * b + 4 * c + 6 * d + N) % 7; + + // Historical corrections for April 26 and 25 + if (e == 6) { + if (d == 29 || (d == 28 && a > 10)) { + e = -1; + } + } + + // Determination of the correct month for Easter + if (22 + d + e > 31) { + return 'April ${d + e - 9}'; + } else { + return 'March ${22 + d + e}'; + } +} + +void main() { + print("The following are the dates of the Paschal full moon (using Servois " + + "notation) and the date of Easter for 2020-2030 AD:"); + + print("Year\tServois number\tEaster"); + + for (var year = 2020; year <= 2030; year++) { + final servoisNumber = computus(year, servois: true); + final easterDate = computus(year); + + print('$year\t$servoisNumber\t\t$easterDate'); + } +} diff --git a/contents/computus/code/javascript/gauss_easter.js b/contents/computus/code/javascript/gauss_easter.js new file mode 100644 index 000000000..f413644f5 --- /dev/null +++ b/contents/computus/code/javascript/gauss_easter.js @@ -0,0 +1,91 @@ +/** + * In this code, the modulus operator is used. + * However, this operator in javascript/typescript doesn't support negative numbers. + * So, where there may be negative numbers, the function mod is used. + * This function gives the modulo of any relative number a + */ + +/** + * @param {number} a + * @param {number} b + * @returns {number} + */ +function mod(a, b) { + if (a < 0) return mod(a + b, b); + else return a % b; +} + +/** + * @param {number} year + * @param {boolean} [servois=false] + * @returns {string} + */ +function computus(year, servois = false) { + // Year's position in metonic cycle + const a = year % 19; + + // Century index + const k = Math.floor(year / 100); + + // Shift of metonic cycle, add a day offset every 300 years + const p = Math.floor((13 + 8 * k) / 25); + + // Correction for non-observed leap days + const q = Math.floor(k / 4); + + // Correction to starting point of calculation each century + const M = mod(15 - p + k - q, 30); + + // Number of days from March 21st until the full moon + const d = (19 * a + M) % 30; + + // Returning if user wants value for Servois' table + if (servois) { + return ((21 + d) % 31).toString(); + } + + // Finding the next Sunday + // Century-based offset in weekly calculation + const N = mod(4 + k - q, 7); + + // Correction for leap days + const b = year % 4; + const c = year % 7; + + // Days from d to next Sunday + let e = (2 * b + 4 * c + 6 * d + N) % 7; + + // Historical corrections for April 26 and 25 + if (e === 6) { + if (d === 29 || (d === 28 && a > 10)) { + e = -1; + } + } + + // Determination of the correct month for Easter + if (22 + d + e > 31) { + return `April ${d + e - 9}`; + } else { + return `March ${22 + d + e}`; + } +} + +console.log( + "The following are the dates of the Paschal full moon (using Servois " + + "notation) and the date of Easter for 2020-2030 AD:" +); + +const values = []; + +for (let year = 2020; year <= 2030; year++) { + const servoisNumber = computus(year, true); + const easterDate = computus(year); + + // Creation of an object to be displayed as a line in the output table + values[year] = { + "servois number": +servoisNumber, + easter: easterDate, + }; +} + +console.table(values); diff --git a/contents/computus/code/typescript/gauss_easter.ts b/contents/computus/code/typescript/gauss_easter.ts new file mode 100644 index 000000000..789b9bd7e --- /dev/null +++ b/contents/computus/code/typescript/gauss_easter.ts @@ -0,0 +1,91 @@ +/** + * In this code, the modulus operator is used. + * However, this operator in javascript/typescript doesn't support negative numbers. + * So, where there may be negative numbers, the function mod is used. + * This function gives the modulo of any relative number a + */ + +function mod(a: number, b: number): number { + if (a < 0) { + return mod(a + b, b); + } else { + return a % b; + } +} +function computus(year: number, servois: boolean = false): string { + // Year's position in metonic cycle + const a: number = year % 19; + + // Century index + const k: number = Math.floor(year / 100); + + // Shift of metonic cycle, add a day offset every 300 years + const p: number = Math.floor((13 + 8 * k) / 25); + + // Correction for non-observed leap days + const q: number = Math.floor(k / 4); + + // Correction to starting point of calculation each century + const M: number = mod(15 - p + k - q, 30); + + // Number of days from March 21st until the full moon + const d: number = (19 * a + M) % 30; + + // Returning if user wants value for Servois' table + if (servois) { + return ((21 + d) % 31).toString(); + } + + // Finding the next Sunday + // Century-based offset in weekly calculation + const N: number = mod(4 + k - q, 7); + + // Correction for leap days + const b: number = year % 4; + const c: number = year % 7; + + // Days from d to next Sunday + let e: number = (2 * b + 4 * c + 6 * d + N) % 7; + + // Historical corrections for April 26 and 25 + if (e === 6) { + if (d === 29 || (d === 28 && a > 10)) { + e = -1; + } + } + + // Determination of the correct month for Easter + if (22 + d + e > 31) { + return `April ${d + e - 9}`; + } else { + return `March ${22 + d + e}`; + } +} + +console.log( + "The following are the dates of the Paschal full moon (using Servois " + + "notation) and the date of Easter for 2020-2030 AD:" +); + +// Type of a line in the output table +interface IOutputLine { + "servois number": number; + easter: string; +} + +const values: IOutputLine[] = []; + +for (let year = 2020; year <= 2030; year++) { + const servoisNumber: string = computus(year, true); + const easterDate: string = computus(year); + + // Creation of an object to be displayed as a line in the output table + const line: IOutputLine = { + "servois number": +servoisNumber, + easter: easterDate, + }; + + values[year] = line; +} + +console.table(values); diff --git a/contents/computus/computus.md b/contents/computus/computus.md index 31071d5f1..0b474c9a9 100644 --- a/contents/computus/computus.md +++ b/contents/computus/computus.md @@ -322,6 +322,12 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us [import, lang:"nim"](code/nim/gauss_easter.nim) {% sample lang="scala" %} [import, lang:"scala"](code/scala/gauss_easter.scala) +{% sample lang="dart" %} +[import, lang:"dart"](code/dart/gauss_easter.dart) +{% sample lang="javascript" %} +[import, lang:"javascript"](code/javascript/gauss_easter.js) +{% sample lang="typescript" %} +[import, lang:"typescript"](code/typescript/gauss_easter.ts) {% endmethod %}