Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created February 1, 2023 18:48
Show Gist options
  • Save twopoint718/8c65cf04f1c98eac873bfd26fcb6978a to your computer and use it in GitHub Desktop.
Save twopoint718/8c65cf04f1c98eac873bfd26fcb6978a to your computer and use it in GitHub Desktop.
Calculate the date of Easter
def computus(year)
a = year % 19 # year in the 19-year metonic cycle
k = year / 100 # century index
p = (13 + 8*k) / 25 # shift of metonic cycle, add a day offset every 300 years
q = k / 4 # correction for non-observed leap days
m = (15 - p + k - q) % 30 # correction to starting point each century
d = (19*a + m) % 30 # num of days from 3/21 until full moon
n = (4 + k - q) % 7 # find next sunday; century-based offset in weekly calc.
b = year % 4 # correct for leap days
c = year % 7 # correct for leap days
e = (2*b + 4*c + 6*d + n) % 7 # days from `d` to next Sunday
# historical corrections for April 26 and 25
if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10)
e = -1
end
# determinaton of the correct month for Easter
if (22 + d + e) > 31
return "April #{d + e - 9}"
else
return "March #{22 + d + e}"
end
end
puts computus(2023)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment