diff options
| author | Steven Wilson <steven1170@zoho.eu> | 2022-07-29 18:27:52 +0100 |
|---|---|---|
| committer | Steven Wilson <steven1170@zoho.eu> | 2022-07-29 18:27:52 +0100 |
| commit | 250fa8ca4a1d6e96863a5074be1376503452b7c6 (patch) | |
| tree | edb350f5fafc9b879d3d04ef846217935ef2f227 | |
| parent | 2ba2a46f6d2eb7ecc4d3db088505df6e86665e75 (diff) | |
| download | perlweeklychallenge-club-250fa8ca4a1d6e96863a5074be1376503452b7c6.tar.gz perlweeklychallenge-club-250fa8ca4a1d6e96863a5074be1376503452b7c6.tar.bz2 perlweeklychallenge-club-250fa8ca4a1d6e96863a5074be1376503452b7c6.zip | |
add solution week 175 task 1
| -rw-r--r-- | challenge-175/steven-wilson/perl/ch-01.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-175/steven-wilson/perl/ch-01.pl b/challenge-175/steven-wilson/perl/ch-01.pl new file mode 100644 index 0000000000..15a456dcbe --- /dev/null +++ b/challenge-175/steven-wilson/perl/ch-01.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# Week 175 Task 1 +# Write a script to list Last Sunday of every month in the given year. + +use strict; +use warnings; +use DateTime; + +my $year = $ARGV[0]; +my $dt = DateTime->new( year => $year, month => 1, day => 1 ); +my %sundays; + +while ( $year == $dt->year ) { + if ( $dt->dow == 7 ) { + $sundays{ $dt->mon } = $dt->day; + $dt->add( days => 7 ); + } + else { + $dt->add( days => 1 ); + } +} + +for my $month ( sort { $a <=> $b } keys %sundays ) { + printf( "$year-%02d-$sundays{$month}\n", $month ); +} |
