aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuane Powell <duane.r.powell@gmail.com>2019-10-14 11:02:36 -0500
committerDuane Powell <duane.r.powell@gmail.com>2019-10-14 11:02:36 -0500
commit3439d8fee2acdb0fa4a937fa42860066d1c65798 (patch)
tree0a122b042e8626adbd13288bf5f0a15975a7e2fb
parent642e8ddf16c4de8de7163a9b916f895f7193e42f (diff)
downloadperlweeklychallenge-club-3439d8fee2acdb0fa4a937fa42860066d1c65798.tar.gz
perlweeklychallenge-club-3439d8fee2acdb0fa4a937fa42860066d1c65798.tar.bz2
perlweeklychallenge-club-3439d8fee2acdb0fa4a937fa42860066d1c65798.zip
Commit solutions for perl weekly challenge 030
-rwxr-xr-xchallenge-030/duane-powell/perl5/ch-1.pl37
-rwxr-xr-xchallenge-030/duane-powell/perl5/ch-2.pl77
2 files changed, 114 insertions, 0 deletions
diff --git a/challenge-030/duane-powell/perl5/ch-1.pl b/challenge-030/duane-powell/perl5/ch-1.pl
new file mode 100755
index 0000000000..46ca15c946
--- /dev/null
+++ b/challenge-030/duane-powell/perl5/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+# Write a script to list dates for Sunday Christmas between 2019 and 2100. For example, 25 Dec 2022 is Sunday.
+
+use DateTime;
+use constant SUNDAY => 7;
+use constant DECEMBER => 12;
+use constant XMAS => 25;
+
+print "List of Sunday Christmas between 2019 and 2100\n";
+foreach my $year (2019 .. 2100) {
+ my $dt = DateTime->new(
+ 'year' => $year,
+ 'month' => DECEMBER,
+ 'day' => XMAS,
+ );
+
+ print "$year/12/25\n" if ($dt->day_of_week == SUNDAY);
+}
+
+__END__
+
+./ch-1.pl
+List of Sunday Christmas between 2019 and 2100
+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
+2095/12/25
diff --git a/challenge-030/duane-powell/perl5/ch-2.pl b/challenge-030/duane-powell/perl5/ch-2.pl
new file mode 100755
index 0000000000..c33051a44b
--- /dev/null
+++ b/challenge-030/duane-powell/perl5/ch-2.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+# 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.
+
+# We can imagine that 10 is the maximum because 10+1+1 = 12
+foreach my $x (1..10) {
+ foreach my $y (1..10) {
+ foreach my $z (1..10) {
+ my $sum = $x + $y + $z;
+ printf ("%2d,%2d,%2d\n", $x, $y, $z) if ($sum == 12) and ($x % 2 == 0 or $y % 2 == 0 or $z % 2 == 0);
+ }
+ }
+}
+
+
+__END__
+
+./ch-2.pl
+ 1, 1,10
+ 1, 2, 9
+ 1, 3, 8
+ 1, 4, 7
+ 1, 5, 6
+ 1, 6, 5
+ 1, 7, 4
+ 1, 8, 3
+ 1, 9, 2
+ 1,10, 1
+ 2, 1, 9
+ 2, 2, 8
+ 2, 3, 7
+ 2, 4, 6
+ 2, 5, 5
+ 2, 6, 4
+ 2, 7, 3
+ 2, 8, 2
+ 2, 9, 1
+ 3, 1, 8
+ 3, 2, 7
+ 3, 3, 6
+ 3, 4, 5
+ 3, 5, 4
+ 3, 6, 3
+ 3, 7, 2
+ 3, 8, 1
+ 4, 1, 7
+ 4, 2, 6
+ 4, 3, 5
+ 4, 4, 4
+ 4, 5, 3
+ 4, 6, 2
+ 4, 7, 1
+ 5, 1, 6
+ 5, 2, 5
+ 5, 3, 4
+ 5, 4, 3
+ 5, 5, 2
+ 5, 6, 1
+ 6, 1, 5
+ 6, 2, 4
+ 6, 3, 3
+ 6, 4, 2
+ 6, 5, 1
+ 7, 1, 4
+ 7, 2, 3
+ 7, 3, 2
+ 7, 4, 1
+ 8, 1, 3
+ 8, 2, 2
+ 8, 3, 1
+ 9, 1, 2
+ 9, 2, 1
+10, 1, 1
+