Problem 158347 · hard · Level 01 Prerequisites & Setup

Counting Unlucky Fridays

loops · conditionals · modulo · lists

Write count_friday_13(start_year, end_year) that returns how many months, in the years start_year to end_year inclusive, have their 13th day on a Friday. If start_year > end_year there are no years to look at, so return 0.

Use the Gregorian calendar for every year:

  • Month lengths are 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 (January to December).
  • February has 29 days in a leap year: a year divisible by 4, except that years divisible by 100 are not leap years, except that years divisible by 400 are leap years again.
  • 1 January 1600 was a Saturday. You may not use any date library.

Examples

Input:  start_year = 2026, end_year = 2026
Output: 3
Explanation: February, March and November 2026 each have a Friday the 13th.

Input:  start_year = 1900, end_year = 1900
Output: 2
Explanation: April and July. 1900 is not a leap year.

Input:  start_year = 2000, end_year = 2099
Output: 172

Constraints

  • 1600 <= start_year <= 9999
  • 1600 <= end_year <= 9999

Goals

  • Carry a running weekday across months and years
  • Apply the full leap-year rule
  • Count only inside a window while simulating from a fixed anchor
Starting Python…