How many Friday 13ths?

Riddler Express

First, an unlucky puzzle that comes a week late:

Depending on the year, there can be one, two or three Friday the 13ths. Last week happened to be the second Friday the 13th of 2020.

What is the greatest number of Friday the 13ths that can occur over the course of four consecutive calendar years?

Extra credit: What’s the greatest number of Friday the 13ths that can occur over a four-year period (i.e., a period that doesn’t necessarily begin on January 1)?

Solution

Accounting for 7 days a week, years, leap years, and century leap years, I decided to use a 2800 year cycle from 1000 to 3800.

In [1]:
import calendar
from datetime import date
from datetime import datetime
from datetime import timedelta
import matplotlib.pyplot as plt
import pandas as pd
In [2]:
#List of all January 1st between 1000 and 3804.
jan_firsts = []
for y in range(1000, 3805):
    temp = datetime(y, 1, 1).date()
    jan_firsts.append(temp)

#List of all Friday 13ths between 1000 and 3804.    
friday_13ths = []
for y in range(1000, 3805) :
    for m in range(1,13) :
        day = datetime(y, m, 13).date()
        if calendar.day_name[day.weekday()] == "Friday" :
            friday_13ths.append(day)
In [3]:
#Count the total number of Friday the 13ths in a four year span,
#starting with the date from a list.
def count_fri_thirteenths(date_list) :
    fridays_list = []
    for d in date_list:
        #Four years later is normally going to change every year by adding four, and one day subtracted from that.
        try :
            four_years_later = datetime(d.year + 4, d.month, d.day).date() - timedelta(days = 1)
        #Century years not divisible by 400 are not leap years.  Got to February 28th.    
        except :
            four_years_later = datetime(d.year + 4, d.month, d.day - 1).date()
        
        #Create a count of Friday the 13ths in the four year span.
        fridays_count = 0
        for f in friday_13ths:
            if (d <= f) and (f <= four_years_later):
                fridays_count += 1
        fridays_list.append(fridays_count)
    
    #Dataframe
    df = pd.DataFrame(data = {'Date': date_list,
                              'Friday_13th_Count': fridays_list})
    
    return(df)

#Graph Helper.
def plotter(df, xlabel):
    fig, ax = plt.subplots(1, 1, figsize = (14, 7))

    ax.plot_date(df['Date'], df['Friday_13th_Count'], 'go', markersize = 5)
    ax.xaxis_date()
    ax.set_title("Number of Friday 13ths in the Next Four Years", fontsize = 24)
    ax.set_xlabel(xlabel = xlabel, fontsize = 18)
    plt.setp(ax.get_xticklabels(), ha = "right", rotation = 45)

    ax.set_ylabel(ylabel = "Count of Friday 13ths", fontsize = 18)
    ax.set_yticks([6, 7, 8, 9])
    ax.tick_params(axis = 'both', labelsize = 14)

Four Consecutive Years

Starting every January 1st from 1000 to 2800, I counted the number of Friday 13ths in the next four years after that date.

In [4]:
df_jan_firsts = count_fri_thirteenths(jan_firsts[0:2801])
plotter(df_jan_firsts,
        "Year (Date always January 1st)")

Four-Year Periods

Any maximum number of Friday 13ths in a four-year period is not limited to, but could start with a Friday 13th.

In [5]:
df_fri_thirteenths = count_fri_thirteenths(friday_13ths[0:4820])
plotter(df_fri_thirteenths,
        "Year (Date is every Friday 13th)")

Answer

The maximum, in either case, is nine Friday 13ths in four consecutive years or a four year span.

Rohan Lewis

2020.11.23