程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python:實現gauss easte高斯復活節日期算法(附完整源碼)

編輯:Python

Python:實現gauss easte高斯復活節日期算法


import math
from datetime import datetime, timedelta
def gauss_easter(year: int) -> datetime:
metonic_cycle = year % 19
julian_leap_year = year % 4
non_leap_year = year % 7
leap_day_inhibits = math.floor(year / 100)
lunar_orbit_correction = math.floor((13 + 8 * leap_day_inhibits) / 25)
leap_day_reinstall_number = leap_day_inhibits / 4
secular_moon_shift = (
15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
) % 30
century_starting_point = (4 + leap_day_inhibits - leap_day_reinstall_number) % 7
# days to be added to March 21
days_to_add = (19 * metonic_cycle + secular_moon_shift) % 30
# PHM -> Paschal Full Moon
days_from_phm_to_sunday = (
2 * julian_leap_year
+ 4 * non_leap_year
+ 6 * days_to_add
+ century_starting_point
) % 7
if days_to_add == 29 and days_from_phm_to_sunday == 6:
return datetime(year, 4, 19)
elif days_to_add == 28 and days_from_phm_to_sunday == 6:
return datetime(year, 4, 18)
else:
return datetime(year, 3, 22) + timedelta(
days=int(days_to_add + days_from_phm_to_sunday)
)
if __name__ == "__main__":
for year in (1994, 2000, 2010, 2021, 2023):
tense = "will be" if year > datetime.now().year else "was"
print(f"Easter in {
year} {
tense} {
gauss_easter(year)}")

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved