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 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
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!