DEV Community

Discussion on: Daily Challenge #27 - Unlucky Days

Collapse
 
choroba profile image
E. Choroba • Edited

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.