medium +20 pts

Easter Date Calculator

Compute the exact date of Easter Sunday for any given year using the Gregorian algorithm.

Write a function `easter_date(year: int) -> str` that takes a year (integer) and returns the date of Easter Sunday for that year in the format `YYYY-MM-DD`. The Gregorian calendar is used for all years. The calculation must follow the standard algorithm (e.g., the Anonymous Gregorian algorithm) used for Easter computus, which works for any year from 1900 to 2100. Your function should return the correct date for all valid years in that range. Input will be a single integer `year` between 1900 and 2100 inclusive. The output must be a string exactly in `YYYY-MM-DD` format (e.g., `2024-03-31`). No external libraries such as `dateutil` are allowed; you must implement the computation yourself. You may use Python's `datetime` module to format the date if you wish. Make sure your function is deterministic and returns the correct date for every valid year.

Constraints

Year is an integer with 1900 <= year <= 2100. Function must return a string of the form `YYYY-MM-DD`.

Example

> easter_date(2024)
'2024-03-31'
> easter_date(2023)
'2023-04-09'
> easter_date(2000)
'2000-04-23'
20 points ~25 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the Anonymous Gregorian algorithm: compute a, b, c, d, e, f, g, h, i, k, l, m and the month/day from those values.
Be careful with integer division and modulo operations in Python (use // and %).
The month is either March (3) or April (4) depending on whether the computed day is <= 31.
Format the output using f-string or strftime with zero-padded month and day.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.