Friday 13th is a date which looms large in the minds of the superstitious. From my experience, that superstition can be a good thing: I once took an international flight on a Friday 13th, and it was mostly empty – I had a whole row to myself, and thoroughly enjoyed stretching out. But anyway… the purpose of this post is to show that every year has at least one, and at most three, Friday 13th’s. As usual, I’ll use Sage for the computations.

Consider years which aren’t leap years. To start, create a list of the number of days in each month:

sage: months = [31,28,31,30,31,30,31,31,30,31,30,31]

Now we make a cumulative sum containing the total numbers of days of the year until the start of each month:

sage: cmonths = [0] sage: for x in months[:11]: ....: cmonths += [x+cmonths[-1]] ....: sage: cmonths [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]

Finally, we turn this last list into a list of days on which each 13th of the month falls:

sage: thirteens = [mod(x+13,7) for x in cmonths] sage: thirteens [6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]

Notice that this is a complete set of residues modulo 7:

sage: set(thirteens)==set(range(7)) True

This means that no matter what day on which a year starts, in other words, no matter what value (mod 7) is added to that list, there will be at least one value equal to 5 – a Friday. For 2011, January 1 was a Saturday, so the zeroth day was a Friday:

sage: [x+5 for x in thirteens] [4, 0, 0, 3, 5, 1, 3, 6, 2, 4, 0, 2]

The five is in the fifth place, indicating the fifth month: May. In 2015, January 1 will be on a Thursday, so the zeroth day is Wednesday:

sage: [x+3 for x in thirteens] [2, 5, 5, 1, 3, 6, 1, 4, 0, 2, 5, 0]

Here there are three Friday 13’s: in February, March and November. Note that this is the maximum possible, as three is the highest count for any value in the “thirteens” list.

And here’s the same thing for leap years:

sage: months = [31,29,31,30,31,30,31,31,30,31,30,31] sage: cmonths = [0] sage: for x in months[:11]: cmonths += [x+cmonths[-1]] ....: sage: thirteens = [mod(x+13,7) for x in cmonths] sage: thirteens [6, 2, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5] sage: set(thirteens)==set(range(7)) True

Again, the list is a complete set of residues modulo 7, and the largest number of occurrences is 3, in the months January, April and July. These months will have a Friday 13 if the year begins on a Sunday, and the next such year will be next year: 2012.