diff options
| -rw-r--r-- | challenge-137/bob-lied/README | 4 | ||||
| -rw-r--r-- | challenge-137/bob-lied/perl/ch-1.pl | 40 |
2 files changed, 42 insertions, 2 deletions
diff --git a/challenge-137/bob-lied/README b/challenge-137/bob-lied/README index bbaa2cbbcb..1383134251 100644 --- a/challenge-137/bob-lied/README +++ b/challenge-137/bob-lied/README @@ -1,3 +1,3 @@ -Solutions to weekly challenge 116 by Bob Lied. +Solutions to weekly challenge 137 by Bob Lied -https://perlweeklychallenge.org/blog/perl-weekly-challenge-116/ +https://perlweeklychallenge.org/blog/perl-weekly-challenge-137/ diff --git a/challenge-137/bob-lied/perl/ch-1.pl b/challenge-137/bob-lied/perl/ch-1.pl new file mode 100644 index 0000000000..b49897d3ef --- /dev/null +++ b/challenge-137/bob-lied/perl/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl +#============================================================================= +# Copyright (c) 2021, Bob Lied +#============================================================================= +# Perl Weekly Challenge 137, Task 1: Long Year +# +# Write a script to find all the years between 1900 and 2100 which is a Long +# Year. A year is Long if it has 53 weeks. +# +#============================================================================= + +use strict; +use warnings; +use v5.32; + +use experimental qw/ signatures /; +no warnings "experimental::signatures"; + +use DateTime; + +my @longYearList; + +for my $year ( 1900 .. 2100 ) +{ + my $dt = DateTime->new(year => $year, month => 12, day => 31); + my ($year, $weeknum) = $dt->week(); + + push @longYearList, $year if $weeknum == 53; +} + +# Output in comma-separated groups of five. +my @row; +while ( @longYearList ) +{ + push @row, join(", ", splice(@longYearList, 0, 5) ); +} +say join(",\n", @row); |
