-
Notifications
You must be signed in to change notification settings - Fork 320
/
ch-1.pl
executable file
·30 lines (21 loc) · 870 Bytes
/
ch-1.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Date::Calc ( 'Day_of_Week', 'leap_year' );
sub main {
my $year = shift;
# Sanity check
die "You must specify the year" unless defined $year;
die "Year must be four digits > 1752" unless $year =~ /^[0-9]{4}$/ and $year > 1752;
# Get the day of week of January 1st, and leap year flag
my $day_of_week = Day_of_Week( $year, 1, 1 ); # 1 - Monday, 7 - Sunday
my $leap = leap_year($year);
# If the 1st of January is Saturday or Sunday, then the Dec 31st (or
# Dec 30th in a leap year) isn't a work day.
my $workdays = ( $day_of_week != 6 and $day_of_week != 7 ) ? 261 : 260;
# In a leap year, the Dec 31st is two days later than Jan 1st.
++$workdays if $leap and $day_of_week != 5 and $day_of_week != 6;
say $workdays;
}
main(@ARGV);