|
| 1 | +fn computus(year: usize, servois: bool) -> String { |
| 2 | + // Year's position on the 19 year metonic cycle |
| 3 | + let a = year % 19; |
| 4 | + |
| 5 | + // Century index |
| 6 | + let k = year / 100; // NOTE: dividing integers always truncates the result |
| 7 | + |
| 8 | + // Shift of metonic cycle, add a day offset every 300 years |
| 9 | + let p = (13 + 8 * k) / 25; |
| 10 | + |
| 11 | + // Correction for non-observed leap days |
| 12 | + let q = k / 4; |
| 13 | + |
| 14 | + // Correction to starting point of calculation each century |
| 15 | + let m = (15 - p + k - q) % 30; |
| 16 | + |
| 17 | + // Number of days from March 21st until the full moon |
| 18 | + let d = (19 * a + m) % 30; |
| 19 | + |
| 20 | + if servois { |
| 21 | + return ((21 + d) % 31).to_string(); |
| 22 | + } |
| 23 | + |
| 24 | + // Finding the next Sunday |
| 25 | + // Century-based offset in weekly calculation |
| 26 | + let n = (4 + k - q) % 7; |
| 27 | + |
| 28 | + // Correction for leap days |
| 29 | + let b = year % 4; |
| 30 | + let c = year % 7; |
| 31 | + |
| 32 | + // Days from d to next Sunday |
| 33 | + let temp_e = ((2 * b + 4 * c + 6 * d + n) % 7) as isize; |
| 34 | + |
| 35 | + // Historical corrections for April 26 and 25 |
| 36 | + let e = if (d == 29 && temp_e == 6) || (d == 28 && temp_e == 6 && a > 10) { |
| 37 | + -1 |
| 38 | + } else { |
| 39 | + temp_e |
| 40 | + }; |
| 41 | + |
| 42 | + // Determination of the correct month for Easter |
| 43 | + if (22 + d) as isize + e > 31 { |
| 44 | + format!("April {}", d as isize + e - 9) |
| 45 | + } else { |
| 46 | + format!("March {}", 22 + d as isize + e) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +fn main() { |
| 51 | + // Here, we will output the date of the Paschal full moon |
| 52 | + // (using Servois notation), and Easter for 2020-2030 |
| 53 | + |
| 54 | + let years = 2020..=2030; |
| 55 | + |
| 56 | + println!( |
| 57 | + "The following are the dates of the Paschal full moon (using \ |
| 58 | + Servois notation) and the date of Easter for 2020-2030 AD:" |
| 59 | + ); |
| 60 | + println!("Year\tServois number\tEaster"); |
| 61 | + years.for_each(|year| { |
| 62 | + println!( |
| 63 | + "{}\t{:<14}\t{}", |
| 64 | + year, |
| 65 | + computus(year, true), |
| 66 | + computus(year, false), |
| 67 | + ) |
| 68 | + }); |
| 69 | +} |
0 commit comments