aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-030/andrezgz/perl5/ch-1.pl28
-rw-r--r--challenge-030/andrezgz/perl5/ch-1.sh5
-rw-r--r--challenge-030/andrezgz/perl5/ch-2.pl42
3 files changed, 75 insertions, 0 deletions
diff --git a/challenge-030/andrezgz/perl5/ch-1.pl b/challenge-030/andrezgz/perl5/ch-1.pl
new file mode 100644
index 0000000000..d95b33b4c2
--- /dev/null
+++ b/challenge-030/andrezgz/perl5/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-030/
+# Task #1
+# Write a script to list dates for Sunday Christmas between 2019 and 2100.
+# For example, 25 Dec 2022 is Sunday.
+
+use strict;
+use warnings;
+
+use DateTime;
+
+do { print $_.$/ if DateTime->new( year => $_, month => 12, day => 25 )->dow == 7 } for ( 2019 .. 2100 );
+
+__END__
+
+./ch-1.pl
+2022
+2033
+2039
+2044
+2050
+2061
+2067
+2072
+2078
+2089
+2095
diff --git a/challenge-030/andrezgz/perl5/ch-1.sh b/challenge-030/andrezgz/perl5/ch-1.sh
new file mode 100644
index 0000000000..1015b530c9
--- /dev/null
+++ b/challenge-030/andrezgz/perl5/ch-1.sh
@@ -0,0 +1,5 @@
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-030/
+# Task #1
+# Write a script to list dates for Sunday Christmas between 2019 and 2100.
+# For example, 25 Dec 2022 is Sunday.
+perl -mDateTime -e 'do { print $_.$/ if DateTime->new( year => $_, month => 12, day => 25 )->dow == 7 } for ( 2019 .. 2100 );'
diff --git a/challenge-030/andrezgz/perl5/ch-2.pl b/challenge-030/andrezgz/perl5/ch-2.pl
new file mode 100644
index 0000000000..74c492c343
--- /dev/null
+++ b/challenge-030/andrezgz/perl5/ch-2.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-030/
+# Task #2
+# 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.
+
+use strict;
+use warnings;
+
+my %groups;
+
+# duplicates are allowed on the same group
+# 0 is ommited in all loops (it's not positive)
+for my $first ( 1..10 ) {
+ for my $second ( 1..10 ) {
+ my $third = 12 - $first - $second; # the sum is 12 (an even number) so one of them is even
+ next if $third <= 0; # none of them is negative
+ my $key = join ' ', # create a unique combination ...
+ sort { $a <=> $b } # by sorting ...
+ $first, $second, $third; # the 3 numbers.
+ print $key.$/ unless $groups{$key}++; # print combination only once.
+ }
+}
+
+
+__END__
+
+./ch-2.pl
+1 1 10
+1 2 9
+1 3 8
+1 4 7
+1 5 6
+2 2 8
+2 3 7
+2 4 6
+2 5 5
+3 3 6
+3 4 5
+4 4 4