re: Daily Challenge #27 - Unlucky Days VIEW POST


Perl solution, using the core library Time::Piece.

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.

Code of Conduct Report abuse