diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-03 07:47:40 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-03 07:47:40 +0000 |
| commit | 1cd169b85c4bcb26ecf76fb13fe1c356c8841ac6 (patch) | |
| tree | a2f2bc5c3c2f1c715f50769ec51f12c17c7deb35 /challenge-137 | |
| parent | 98c4ecee7e067ccce54e89c83ae6502184f44758 (diff) | |
| download | perlweeklychallenge-club-1cd169b85c4bcb26ecf76fb13fe1c356c8841ac6.tar.gz perlweeklychallenge-club-1cd169b85c4bcb26ecf76fb13fe1c356c8841ac6.tar.bz2 perlweeklychallenge-club-1cd169b85c4bcb26ecf76fb13fe1c356c8841ac6.zip | |
- Added solution by Robert DiCicco.
Diffstat (limited to 'challenge-137')
| -rw-r--r-- | challenge-137/robert-dicicco/perl/ch-1.pl | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-137/robert-dicicco/perl/ch-1.pl b/challenge-137/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..4c48577315 --- /dev/null +++ b/challenge-137/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,47 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use 5.30.0; + +use Date::Calc qw (leap_year Day_of_Week); + +# Author: Robert DiCicco +# Date: 01-NOV-2021 +# Challenge 137 + +# ISO-8601 +# An ISO calendar year is long if and only if the corresponding Gregorian +# year begins on a Thursday when it is a common year or begins either on a +# Wednesday or a Thursday when it is a leap year. + +# An ISO calendar year is long if and only if the corresponding Gregorian +# year either begins or ends (or both) on a Thursday. + +my @years = (1900..2100); +my @output_arr = (); + +foreach (@years){ + my $leap_flag = 0; + if (leap_year($_)) { + $leap_flag = 1; + } + + my $sdow = Day_of_Week($_, 1, 1); # Jan. 1st dow for selected year + my $ldow = Day_of_Week($_,12,31); # Dec. 31st dow for selected year + + if ($leap_flag){ # if this ia a leap year + if (($sdow == 3) || ($ldow == 5)){ # and the start dow is Wed., or last dow is Fri. + push(@output_arr, $_); # then add to the output array + } + } + else { # not a leap year + if (($sdow == 4) || ($ldow == 4)){ # and the start dow is Thur., or last dow is Thur. + push(@output_arr, $_); # then add to the output array + } + } +} + +print("\n"); +print("Find all the years between 1900 and 2100 which is a Long Year.\n"); +print("Output:\n@output_arr\n"); |
