diff options
| author | Bob Lied <boblied+github@gmail.com> | 2023-08-28 08:51:03 -0500 |
|---|---|---|
| committer | Bob Lied <boblied+github@gmail.com> | 2023-08-28 08:51:03 -0500 |
| commit | 527c0d1324f7ec152bcddfdc75102772c930ac49 (patch) | |
| tree | abb3a8afbd7b1cd379f083ba1938aea23cc0223b /challenge-227 | |
| parent | e59219f31f8b914e518f840226263b4d933530f9 (diff) | |
| parent | a9d22b907aaedb9edbed4f0f7b4bf523d5b978cf (diff) | |
| download | perlweeklychallenge-club-527c0d1324f7ec152bcddfdc75102772c930ac49.tar.gz perlweeklychallenge-club-527c0d1324f7ec152bcddfdc75102772c930ac49.tar.bz2 perlweeklychallenge-club-527c0d1324f7ec152bcddfdc75102772c930ac49.zip | |
Merge branch 'master' of https://github.com/boblied/perlweeklychallenge-club into w227
Diffstat (limited to 'challenge-227')
| -rw-r--r-- | challenge-227/adam-russell/perl/ch-1.pl | 42 | ||||
| -rw-r--r-- | challenge-227/packy-anderson/README.md (renamed from challenge-227/packy-anderson/README) | 18 |
2 files changed, 51 insertions, 9 deletions
diff --git a/challenge-227/adam-russell/perl/ch-1.pl b/challenge-227/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..912b98b819 --- /dev/null +++ b/challenge-227/adam-russell/perl/ch-1.pl @@ -0,0 +1,42 @@ +use v5.38; +## +# You are given a year number in the range 1753 to 9999. +# Write a script to find out how many dates in the year are Friday 13th. +## +use Getopt::Long; + +use constant JANUARY => 1; +use constant FEBRUARY => 2; +use constant DECEMBER => 12; + +use constant FRIDAY => 5; + +sub month_name{ + my($m) = @_; + return qw/January February March April May June July August September October November + December/[$m - 1]; +} + +sub day_of_week{ + my($year, $month, $day) = @_; + my @month_value = (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); + $year-- if($month == JANUARY || $month == FEBRUARY); + return ($year + int($year / 4) - int($year / 100) + int($year / 400) + $month_value[$month - 1] + $day) % 7 +} + + +MAIN:{ + my($year); + GetOptions(qq/year=i/ => \$year); + my $day = 13; + my $friday_13ths; + my $is_leap_year = ((($year % 4) == 0) && (($year % 100) != 0)) || (($year % 4) == 0 && ($year % 400) == 0); + for my $month (JANUARY .. DECEMBER){ + my $dow = day_of_week($year, $month, $day); + if($dow == FRIDAY){ + $friday_13ths++; + say month_name($month) . q/ / . $day; + } + } + say qq/Friday the 13ths in $year: $friday_13ths/; +}
\ No newline at end of file diff --git a/challenge-227/packy-anderson/README b/challenge-227/packy-anderson/README.md index 1b230ba294..1090bbe2aa 100644 --- a/challenge-227/packy-anderson/README +++ b/challenge-227/packy-anderson/README.md @@ -2,19 +2,19 @@ ## Perl -* [Task 1](perl/task-1.pl) +* [Task 1](perl/ch-1.pl) Sample output ``` -$ perl/task-1.pl 2023 +$ perl/ch-1.pl 2023 Input: $year = 2023 Output: 2 ``` -* [Task 2](perl/task-2.pl) +* [Task 2](perl/ch-2.pl) Sample output ``` -$ perl/task-2.pl < task-2-input.txt +$ perl/ch-2.pl < task-2-input.txt IV + V => IX M - I => CMXCIX X / II => V @@ -34,20 +34,20 @@ $ echo "X + Y" | perl/task-2.pl ## Raku -* [Task 1](raku/task-1.raku) +* [Task 1](raku/ch-1.raku) Sample output ``` -$ raku/task-1.raku 2023 +$ raku/ch-1.raku 2023 Input: $year = 2023 Output: 2 ``` -* [Task 2](raku/task-2.raku) +* [Task 2](raku/ch-2.raku) Sample output ``` -$ raku/task-2.raku < task-2-input.txt +$ raku/ch-2.raku < task-2-input.txt IV + V => IX M - I => CMXCIX X / II => V @@ -65,4 +65,4 @@ V - X => non potest (they didn't do negative numbers) ## Blog Post -[Perl Weekly Challenge 227](http://packy.dardan.com/2023/07/27/perl-weekly-challenge-227/)
\ No newline at end of file +[Perl Weekly Challenge 227](http://packy.dardan.com/2023/07/27/perl-weekly-challenge-227/) |
