diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-14 17:27:02 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-14 17:27:02 -0400 |
| commit | c0d388628fb074634c756c9dc2d382b3455e803b (patch) | |
| tree | 67b0b6cb157b34a892534a24d31b287633534796 /challenge-030 | |
| parent | 4186d4ae2bc3d99dabd4b0cd5cd944f797c84fcf (diff) | |
| download | perlweeklychallenge-club-c0d388628fb074634c756c9dc2d382b3455e803b.tar.gz perlweeklychallenge-club-c0d388628fb074634c756c9dc2d382b3455e803b.tar.bz2 perlweeklychallenge-club-c0d388628fb074634c756c9dc2d382b3455e803b.zip | |
two challenges done!
Diffstat (limited to 'challenge-030')
| -rwxr-xr-x | challenge-030/dave-jacoby/perl5/ch-1.pl | 41 | ||||
| -rwxr-xr-x | challenge-030/dave-jacoby/perl5/ch-2.pl | 51 |
2 files changed, 92 insertions, 0 deletions
diff --git a/challenge-030/dave-jacoby/perl5/ch-1.pl b/challenge-030/dave-jacoby/perl5/ch-1.pl new file mode 100755 index 0000000000..6de70e8384 --- /dev/null +++ b/challenge-030/dave-jacoby/perl5/ch-1.pl @@ -0,0 +1,41 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use feature qw{ postderef say signatures state switch }; +no warnings + qw{ experimental::postderef experimental::smartmatch experimental::signatures }; + +# Write a script to list dates for Sunday Christmas between 2019 and 2100. +# For example, 25 Dec 2022 is Sunday. + +# Christmas Day is always Dec 25. + +use DateTime; + +for my $year ( 2019 .. 2100 ) { + my $dt = DateTime->new( + year => $year, + month => 12, + day => 25, + hour => 12, + minute => 0, + second => 0, + time_zone => 'floating' + ); + if ( 6 == $dt->day_of_week_0() ) { say $dt->date } +} + +__DATA__ + +2022-12-25 +2033-12-25 +2039-12-25 +2044-12-25 +2050-12-25 +2061-12-25 +2067-12-25 +2072-12-25 +2078-12-25 +2089-12-25 diff --git a/challenge-030/dave-jacoby/perl5/ch-2.pl b/challenge-030/dave-jacoby/perl5/ch-2.pl new file mode 100755 index 0000000000..a3ca0a143c --- /dev/null +++ b/challenge-030/dave-jacoby/perl5/ch-2.pl @@ -0,0 +1,51 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use feature qw{ postderef say signatures state switch }; +no warnings + qw{ experimental::postderef experimental::smartmatch experimental::signatures }; + +# Write a script to print all possible series of 3 positive numbers, +# where in each series at least one of the number is even and sum of +# the three numbers is always 12. For example, 3,4,5. + +# First note: three odd integers cannot equal an even number, so the +# "at least one must be even" is a red herring. One or three have to be +# even. + +# Second note: if we allow duplication, 4 + 4 + 4 equals 12, and there's +# no rule in the books that says Dogs can't play Perl Weekly Ch... +# I mean, that we cannot have duplicate positive integers. + +my %done ; + +for my $m ( 1 .. 9 ) { + for my $n ( 1 .. 9 ) { + for my $o ( 1 .. 9 ) { + my $i = join ' ' , sort $m,$n,$o; + next if $done{$i}++;; + my $p = $m + $n + $o; + next unless $p == 12; + say qq{ $m + $n + $o = $p}; + } + } +} + +# but the trick to avoid duplicates is for $n to start with $m+1 +# and $o to start with $n+1. + +__DATA__ + + 1 + 2 + 9 = 12 + 1 + 3 + 8 = 12 + 1 + 4 + 7 = 12 + 1 + 5 + 6 = 12 + 2 + 2 + 8 = 12 + 2 + 3 + 7 = 12 + 2 + 4 + 6 = 12 + 2 + 5 + 5 = 12 + 3 + 3 + 6 = 12 + 3 + 4 + 5 = 12 + 4 + 4 + 4 = 12 |
