Arithmetic
Calendar Calculations
The Night That Never Was: How the Pope Stole 10 Days
On **October 4, 1582**, people in Spain, Portugal, and Italy went to sleep. They woke up on **October 15**. Ten days had simply vanished. This was no magic - it was **Pope Gregory XIII** correcting the accumulated error of the Julian calendar. Over 1,600 years of use, the old calendar had drifted 10 days: Easter was creeping ever further from the spring equinox. Astronomer **Aloysius Lilius** devised new rules; the Pope approved them with the bull Inter gravissimas.
We have decreed to restore the equinox to its rightful place, from which it had retreated by approximately ten days. - Bull Inter gravissimas, 1582
The Gregorian calendar is one of the most successful reforms in history. Its accuracy: a 1-day error will accumulate in 3,236 years. Today nearly every country uses it, although Orthodox churches still calculate Easter by the Julian calendar.
What day of the week were you born? What day will your 100th birthday fall on? These questions seem to require a calendar, but 19th-century mathematicians derived formulas allowing you to calculate the day of the week for any date mentally. Modular arithmetic turns the calendar into a simple problem.
- **Planning:** computing dates of holidays and events
- **History:** determining the day of the week for historical events
- **Programming:** date-handling functions
Day-of-Week Algorithm
**Determining the day of the week** from a date is a classic modular arithmetic problem. The key insight: each year shifts the day of the week by 1 (or by 2 in a leap year).
**Basic facts:** • 1 week = 7 days • Regular year = 365 days = 52 weeks + 1 day • Leap year = 366 days = 52 weeks + 2 days **Consequence:** If January 1 falls on Monday, then next year it will fall on Tuesday (or Wednesday after a leap year).
Several algorithms exist: Doomsday (Conway), Zeller's congruence, and others. All rely on modular arithmetic.
Why does a regular year shift the day of the week by 1?
Leap Year Rules
A **leap year** adds February 29 to compensate for the fact that the solar year is not exactly 365 days, but approximately 365.2422 days.
**Gregorian rules (since 1582):** 1. Year divisible by 4 → leap year 2. BUT: divisible by 100 → NOT a leap year 3. BUT: divisible by 400 → leap year **Examples:** • 2024: ÷4 ✓ → leap year • 1900: ÷4 ✓, ÷100 ✓ → NOT a leap year • 2000: ÷4 ✓, ÷100 ✓, ÷400 ✓ → leap year
The three-divisibility rule is an elegant compromise between accuracy and simplicity. A 1-day error will only accumulate after 3,200 years.
Which of these years is NOT a leap year?
Julian and Gregorian Calendars
The **Julian calendar** (45 BC) used only the ÷4 rule. The **Gregorian** (1582) added exceptions for ÷100 and ÷400. The transition caused days to "disappear".
**Julian calendar:** • Introduced by Julius Caesar in 45 BC • Rule: year ÷ 4 → leap year • Average year length: 365.25 days • Error: ~3 days per 400 years **Gregorian calendar:** • Introduced by Pope Gregory XIII in 1582 • Added ÷100 and ÷400 exceptions • Average length: 365.2425 days • Error: ~1 day per 3,200 years
The two calendars still coexist: the Gregorian is the civil calendar, the Julian is used in Orthodox churches. For historical dates it's important to specify which calendar is being used.
Why is the October Revolution (October 25) celebrated on November 7?
Zeller's Congruence
**Zeller's congruence** is a formula for calculating the day of the week for any date. Named after German mathematician Christian Zeller (1882).
**Zeller's formula (Gregorian):** h = (q + ⌊13(m+1)/5⌋ + K + ⌊K/4⌋ + ⌊J/4⌋ - 2J) mod 7 where: • q = day of the month • m = month (March=3...December=12, January=13, February=14 of the previous year) • K = year mod 100 (year within the century) • J = ⌊year/100⌋ (century) • h = day of week (0=Sat, 1=Sun, 2=Mon...6=Fri)
Zeller's congruence is a classic of computational mathematics. It frequently appears in programming interviews as an example of modular arithmetic in action.
Calculating the day of the week requires a computer or a lookup table
Zeller's congruence allows you to compute the day of the week mentally in about a minute
The formula looks complex, but with practice it becomes second nature. Key steps: shift the year for January/February, divide by 4 and 5, take the final mod 7. Many calendar calculators - and coding interviews - use exactly this algorithm.
Why does Zeller's formula treat January and February as months 13 and 14?
Key Ideas
- Each year shifts the day of the week by 1 (or 2 in a leap year)
- Leap year: ÷4, but not ÷100, but ÷400
- Gregorian is more accurate than Julian by 3 days per 400 years
- Zeller's formula: q + 13(m+1)/5 + K + K/4 + J/4 - 2J mod 7
Related Topics
Calendar calculations make use of:
- Modular Arithmetic — Foundation of all the formulas
- Divisibility — Leap year rules
- History of Arithmetic — Development of calendars
Вопросы для размышления
- Why exactly 7 days in a week - why not 5 or 10?
- How will the calendar change over the next 1,000 years?
- Which cultures use other calendar systems?