28
3
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 code-golf, so the shortest code (in bytes) wins.
7What 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 – 2013-12-10T22:47:18.733
@PeterTaylor I hadn't thought about it. If a date pre-dates gregorian then you can have undefined behaviour. – Cruncher – 2013-12-11T14:05:55.620
1The 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 – 2013-12-11T14:16:05.420
@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 – 2013-12-11T14:17:24.620
3I 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 – 2013-12-11T14:38:55.423