How many friday the 13th in a year?

Your challenge is to write a program which, given a year, outputs the number of "Friday 13ths" in it.

Rules & Details:

• You can take input via STDIN, or as an argument passed to your program.
• You should output the result to STDOUT.
• You may assume that input will be a valid year, and does not pre-date the Gregorian calendar (undefined behaviour is permitted in these cases).
• Calendar/Date libraries are allowed.

This is a , so the shortest code (in bytes) wins.

• What is the required range of input? If it goes much before 1800, what assumptions should be made about switchover from Julian to Gregorian calendar? – Peter Taylor Dec 10 '13 at 22:47
• @PeterTaylor I hadn't thought about it. If a date pre-dates gregorian then you can have undefined behaviour. – Cruncher Dec 11 '13 at 14:05
• The first countries to adopt the Gregorian calendar did so in October 1582, following the bull of Gregory himself. Countries to adopt the new calendar late did not change until the 20th century, for example Greece introduced it on 1 March 1923. – Jeppe Stig Nielsen Dec 11 '13 at 14:16
• @JeppeStigNielsen I don't know much about calendars and such. Whether they adopted them or not doesn't change what the gregorian dates are. Libraries should be able to calculate dates from quite a ways back I presume? – Cruncher Dec 11 '13 at 14:17
• I am being offtopic here, I guess. Many libraries written by Anglo-American programmers use September 1752 as the "correct" time of change of calendars. This was when the British Empire changed. The new calendar was kept when U.S.A. was founded, of course. (As a curiosity, some SQL software has 1753 as the minimal year since they don't want to cope with the September 1752 issue.) However, using September 1752 is highly anglocentric. You are right Gregorian dates are the same whether they were used historically or not. That is the so-called proleptic Gregorian calendar. – Jeppe Stig Nielsen Dec 11 '13 at 14:38

JavaScript, 56 bytes

y=>(g=m=>m?g(--m)-(new Date(y,m,13).getDay()!=5):12)(12)


Try It Online!

VB.net

Not a CodeGolf attempt

Iterator Function SpecificDayOfTheWeekInYear(Year As Integer, DayOfTheWeek As DayOfWeek ) As IEnumerable(of Date)
Dim FirstDayOfTheYear = New Date(Year,1,1)
Dim CurrentDay = FirstDayOfTheYear.AddDays( DayOfTheWeek - FirstDayOfTheYear.DayOfWeek )
If CurrentDay.Year < Year Then CurrentDay = CurrentDay.AddDays(7)
While CurrentDay.Year = Year
Yield CurrentDay
End While
End Function


Which makes looking for Friday the 13th's simple.

Dim FridayThe13ths =  From d in SpecificDayOfTheWeekInYear(2013,DayOfWeek.Friday )
Where d.Day=13


or a much simpler

Iterator Function YieldDayInMonth(Year As Integer, Day As Integer) As IEnumerable(of date)
For M=1 To 12
Yield New Date(Year,M,Day )
Next
End Function


This makes the coding thus.

Dim f13 = YieldDayInMonth( 2013, 13).Where( Function(d) d.DayOfWeek = DayOfWeek.Friday)

• Why are you posting "Not a CodeGolf attempt" on a code golf? That seems a bit off topic and pointless. – Tim Seguine Apr 10 '14 at 18:55
• @TimSeguine Bit like posting any vb.net entry is pointless, not like vb.net is ever going to "win" one of these is it? – Adam Speight Apr 10 '14 at 20:08
• It's more about cleverness than winning. If people like your entry, then you are likely to get upvotes even if you don't win. Choosing not to golf on a code golf question seems like not even trying. – Tim Seguine Apr 10 '14 at 20:11
• Relevant meta post: meta.codegolf.stackexchange.com/a/1456/11909 I am not the only one who downvotes when things don't follow the spec. – Tim Seguine Apr 18 '14 at 15:56