Skip to content

Commit 8ef64b1

Browse files
committed
Changed Computus in JavaScript, Typescript and added Computus in Dart
1 parent d52db37 commit 8ef64b1

File tree

5 files changed

+106
-27
lines changed

5 files changed

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

contents/computus/code/javascript/gauss_easter.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ function computus(year, servois = false) {
4040
const d = (19 * a + M) % 30;
4141

4242
// Returning if user wants value for Servois' table
43-
if (servois) return ((21 + d) % 31).toString();
43+
if (servois) {
44+
return ((21 + d) % 31).toString();
45+
}
4446

4547
// Finding the next Sunday
4648
// Century-based offset in weekly calculation
@@ -54,11 +56,18 @@ function computus(year, servois = false) {
5456
let e = (2 * b + 4 * c + 6 * d + N) % 7;
5557

5658
// Historical corrections for April 26 and 25
57-
if (e === 6) if (d === 29 || (d === 28 && a > 10)) e = -1;
59+
if (e === 6) {
60+
if (d === 29 || (d === 28 && a > 10)) {
61+
e = -1;
62+
}
63+
}
5864

5965
// Determination of the correct month for Easter
60-
if (22 + d + e > 31) return `April ${d + e - 9}`;
61-
else return `March ${22 + d + e}`;
66+
if (22 + d + e > 31) {
67+
return `April ${d + e - 9}`;
68+
} else {
69+
return `March ${22 + d + e}`;
70+
}
6271
}
6372

6473
console.log(

contents/computus/code/typescript/gauss_easter.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,60 @@
66
*/
77

88
function mod(a: number, b: number): number {
9-
if (a < 0) return mod(a + b, b);
10-
else return a % b;
9+
if (a < 0) {
10+
return mod(a + b, b);
11+
} else {
12+
return a % b;
13+
}
1114
}
12-
1315
function computus(year: number, servois: boolean = false): string {
1416
// Year's position in metonic cycle
15-
const a = year % 19;
17+
const a: number = year % 19;
1618

1719
// Century index
18-
const k = Math.floor(year / 100);
20+
const k: number = Math.floor(year / 100);
1921

2022
// Shift of metonic cycle, add a day offset every 300 years
21-
const p = Math.floor((13 + 8 * k) / 25);
23+
const p: number = Math.floor((13 + 8 * k) / 25);
2224

2325
// Correction for non-observed leap days
24-
const q = Math.floor(k / 4);
26+
const q: number = Math.floor(k / 4);
2527

2628
// Correction to starting point of calculation each century
27-
const M = mod(15 - p + k - q, 30);
29+
const M: number = mod(15 - p + k - q, 30);
2830

2931
// Number of days from March 21st until the full moon
30-
const d = (19 * a + M) % 30;
32+
const d: number = (19 * a + M) % 30;
3133

3234
// Returning if user wants value for Servois' table
33-
if (servois) return ((21 + d) % 31).toString();
35+
if (servois) {
36+
return ((21 + d) % 31).toString();
37+
}
3438

3539
// Finding the next Sunday
3640
// Century-based offset in weekly calculation
37-
const N = mod(4 + k - q, 7);
41+
const N: number = mod(4 + k - q, 7);
3842

3943
// Correction for leap days
40-
const b = year % 4;
41-
const c = year % 7;
44+
const b: number = year % 4;
45+
const c: number = year % 7;
4246

4347
// Days from d to next Sunday
44-
let e = (2 * b + 4 * c + 6 * d + N) % 7;
48+
let e: number = (2 * b + 4 * c + 6 * d + N) % 7;
4549

4650
// Historical corrections for April 26 and 25
47-
if (e === 6) if (d === 29 || (d === 28 && a > 10)) e = -1;
51+
if (e === 6) {
52+
if (d === 29 || (d === 28 && a > 10)) {
53+
e = -1;
54+
}
55+
}
4856

4957
// Determination of the correct month for Easter
50-
if (22 + d + e > 31) return `April ${d + e - 9}`;
51-
else return `March ${22 + d + e}`;
58+
if (22 + d + e > 31) {
59+
return `April ${d + e - 9}`;
60+
} else {
61+
return `March ${22 + d + e}`;
62+
}
5263
}
5364

5465
console.log(
@@ -65,8 +76,8 @@ interface IOutputLine {
6576
const values: IOutputLine[] = [];
6677

6778
for (let year = 2020; year <= 2030; year++) {
68-
const servoisNumber = computus(year, true);
69-
const easterDate = computus(year);
79+
const servoisNumber: string = computus(year, true);
80+
const easterDate: string = computus(year);
7081

7182
// Creation of an object to be displayed as a line in the output table
7283
const line: IOutputLine = {

contents/computus/computus.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
320320
[import, lang:"lisp"](code/clisp/gauss-easter.lisp)
321321
{% sample lang="nim" %}
322322
[import, lang:"nim"](code/nim/gauss_easter.nim)
323-
{% sample lang="javascript" %}
324-
[import, lang:"nim"](code/javascript/gauss_easter.js)
325-
{% sample lang="typescript" %}
326-
[import, lang:"nim"](code/typescript/gauss_easter.ts)
327323
{% endmethod %}
328324

329325

-114 KB
Binary file not shown.

0 commit comments

Comments
 (0)