Perl solution, using the core library Time::Piece.
#!/usr/bin/perl use warnings; use strict; use Time::Piece; sub unlucky_days { my ($year) = @_; return grep $_->fullday eq 'Friday', map 'Time::Piece'->strptime("$year-$_-13", '%Y-%m-%d'), 1 .. 12 } use Test::More tests => 2; is unlucky_days(2015), 3, 'year 2015'; is unlucky_days(1986), 1, 'year 1986';
It works because grep in scalar context returns the number of trues.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perl solution, using the core library Time::Piece.
It works because grep in scalar context returns the number of trues.