# How to count occurrences of Friday 13th

I would like to find a function that will count the number of times Friday 13th happens in a particular calendar year.

Does anybody have any hints ?

Thank you

• I fell into a delightful rabbit hole of day-counting algorithms on Wikipedia. I wanted to leave a link to the Doomsday algorithm for mental calculation of the day of the week, for fun: Doomsday rule on Wiki. Commented Mar 4, 2019 at 19:54
• Commented Mar 5, 2019 at 2:21
• Sounds like one for the code golf boys and girls Commented Mar 5, 2019 at 13:05
• Oh, of course they did it already: codegolf.stackexchange.com/questions/69510/… Commented Mar 5, 2019 at 13:11

Select[
Table[DateObject@{2019, m, 13}, {m, 12}],
DateString[#, "DayName"] === "Friday" &
]


{Day: Fri 13 Sep 2019,Day: Fri 13 Dec 2019}

countFri13[year_Integer]:=Length @ Select[
Table[DateObject@{year, m, 13}, {m, 12}],
DateString[#, "DayName"] === "Friday" &
]


I worked on this problem in 2015. Here is part on my notebook from that time.

A not so good algorithm.

friday13th[year_Integer] :=
Select[DayName[#] === Friday &] @
DateRange[DateObject[{year, 1, 13}], DateObject[{year, 12, 13}], {1, "Month"}]


A good algorithm.

friday13th[year_Integer] :=
Select[DayName[#] === Friday &] @ Table[DateObject[{year, i, 13}], {i, 12}]


A better algorithm.

friday13th[year_Integer] :=
Select[DayName[#] === Friday &] @ Array[DateObject[{year, #, 13}] &, 12]


Using the better algorithm, I got (at the time I created the notebook)

friday13th @ 2014


friday13th @ 2015


And for this year, I get

friday13th @ 2019


Thanks @m_goldberg!

I ended up slightly modifying your code to find answer a halloween-themed question my 8 year old daughter had. "When will there be a Friday the 13th that happens on the full moon in October?"

friday13thfullmoon[year_Integer] :=
Select[DayName[#] === Friday && DateValue[#, "Month"] === 10 &&
MoonPhase[#, "Name"] === Entity["MoonPhase", "Full"] &]@
Array[DateObject[{year, #, 13}] &, 12]


that's a little beyond her wolfram language capability (and I had to study yours for a few mins too), but she was able to understand the next step

Table[friday13thfullmoon[year], {year, 2020, 3020}] // Flatten


Turns out that in the next 1000 years it only happens three times!