How many friday the 13th in a year?

Mathematica 49 46 45 44 42

As a pure function: 42 chars

DayName@{#,m,6}~Table~{m,12}~Count~Friday&

Example

DayName@{#,m,6}~Table~{m,12}~Count~Friday&[2013]

2


As a named function: 44 chars

f=DayName@{#,m,6}~Table~{m,12}~Count~Friday&

Examples

f[1776]
f[2012]
f[2013]
f[2014]

2
3
2
1


Ruby, 49 48 47 46

f=->m{(1..12).count{|i|Time.gm(m,i,6).friday?}}

Edit: Shaved a character by going back a week, thanks to Jan, and another by switching from Time.new to Time.gm

Edit: At the expense of obfuscating it a bit more, I can get to 46 with

f=->m{(1..12).count{|i|Time.gm(m,i,8).wday<1}}

Powershell, 68 63 58 52 50

Thanks Iszi for the tip.

$n=$args;(1..12|?{!+(date $n-$_).DayOfWeek}).Count

Using the fact that if the 1st day in the month is Sunday, the 13th will be Friday.

I've also tried:

(1..12|?{!+(date $args-$_).DayOfWeek}).Count

but it's not the same $args inside the script block.

Tags:

Date

Code Golf