diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2021-11-14 23:58:55 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2021-11-14 23:58:55 +0000 |
| commit | dc51668c420ce3232aa5060aa9b569585ab8974b (patch) | |
| tree | 9308f0021468a5133a6e43759d20615dd091eb9a | |
| parent | ab6264c731bd86ab90b28c82d43af85d482756c4 (diff) | |
| download | perlweeklychallenge-club-dc51668c420ce3232aa5060aa9b569585ab8974b.tar.gz perlweeklychallenge-club-dc51668c420ce3232aa5060aa9b569585ab8974b.tar.bz2 perlweeklychallenge-club-dc51668c420ce3232aa5060aa9b569585ab8974b.zip | |
Task 1
| -rwxr-xr-x | challenge-138/perlboy1967/perl/ch-1.pl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-138/perlboy1967/perl/ch-1.pl b/challenge-138/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..0b8d525455 --- /dev/null +++ b/challenge-138/perlboy1967/perl/ch-1.pl @@ -0,0 +1,50 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 138 + - https://perlweeklychallenge.org/blog/perl-weekly-challenge-138/#TASK1 + +Author: Niels 'PerlBoy' van Dijke + +TASK #1 › Workdays +Submitted by: Mohammad S Anwar + +You are given a year, $year in 4-digits form. + +Write a script to calculate the total number of workdays in the given year. + + || For the task, we consider, Monday - Friday as workdays. + +=cut + +use v5.16; +use strict; +use warnings; + +use Date::Calc qw(Day_of_Week Week_of_Year); + +use Test::More; + +my %tests = ( + 2000 => 260, 2001 => 261, 2002 => 261, 2003 => 261, + 2004 => 262, 2005 => 260, 2006 => 260, 2007 => 261, + 2008 => 262, 2009 => 261, 2010 => 261, 2011 => 260, + 2012 => 261, 2013 => 261, 2014 => 261, 2015 => 261, + 2016 => 261, 2017 => 260, 2018 => 261, 2019 => 261, + 2020 => 262, 2021 => 261, 2022 => 260, 2023 => 260, + 2024 => 262, 2025 => 261, 2026 => 261, 2027 => 261, +); + +foreach my $y (sort { $a <=> $b } keys %tests) { + my ($dayOfWeek1,$dayOfWeek2) = (Day_of_Week($y,1,1),Day_of_Week($y,12,31)); + + my $workingDays = 262; + $workingDays-- if ($dayOfWeek1 > 5); + $workingDays-- if ($dayOfWeek2 > 5); + $workingDays-- if ($dayOfWeek1 == $dayOfWeek2 and $dayOfWeek1 < 6); + + is($workingDays,$tests{$y},"year=$y"); +} + +done_testing; |
