aboutsummaryrefslogtreecommitdiff
path: root/challenge-037/saiftynet/perl5/ch-1.pl
blob: b8fe9cf7788d8af1fb196792efda01897ea3cb4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/env perl
# weekdays in month
# Challenge 1 week 37

use strict;
use warnings;
use DateTime;
 
my $dt = DateTime->new(            # start at first day of the year
    year       => 2019,
    month      => 1,
    day        => 1,);
    
my %counters;                      # set up weekday counters

while ($dt->year() ==2019){        # Until the year is over
  $counters{$dt->month()}+=1       # add to each month's counter
     if ($dt->day_of_week() <6);   # if the day is a week day. 
  $dt->add( days => 1 )            # Get next day
}

print "Answer to 1st Challenge of week 37\nIn 2019\n";
for (1..12){                       # now print out each month
   print qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/[$_-1].
         " has " .$counters{$_} . " Weekdays \n"; # and its weeday counts
}

#Output
#Answer to 1st Challenge of week 37
#In 2019
#Jan has 23 Weekdays 
#Feb has 20 Weekdays 
#Mar has 21 Weekdays 
#Apr has 22 Weekdays 
#May has 23 Weekdays 
#Jun has 20 Weekdays 
#Jul has 23 Weekdays 
#Aug has 22 Weekdays 
#Sep has 21 Weekdays 
#Oct has 23 Weekdays 
#Nov has 21 Weekdays 
#Dec has 22 Weekdays