Skip to content

Instantly share code, notes, and snippets.

@nitschmann
Last active March 15, 2016 13:45
Show Gist options
  • Save nitschmann/a1a1747a96862cbe65ad to your computer and use it in GitHub Desktop.
Save nitschmann/a1a1747a96862cbe65ad to your computer and use it in GitHub Desktop.
Ruby implementation to find out the easter day date for a specific year (based on Anonymous Gregorian algorithm)
require "date"
# anonymous gregorian algorithm (http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm)
def easter_day(year)
if year.is_a?(Integer)
y = year
# calculation
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451;
# date
month = (h + l - 7 * m + 114) / 31;
day = ((h + l - 7 * m + 114) % 31) + 1;
Date.new(year,month,day).to_s
else
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment