aboutsummaryrefslogtreecommitdiff
path: root/challenge-030
diff options
context:
space:
mode:
authorConor Hoekstra <codereport@outlook.com>2021-12-24 22:16:15 -0500
committerConor Hoekstra <codereport@outlook.com>2021-12-24 22:16:15 -0500
commitc804b128cf740d95b244cd3fe15e86d0820ab51e (patch)
treeb9db7c3a5f93e6a83640f56bfd5decb9bbe8dbfe /challenge-030
parent116add27d0d74360c7d4ad26b12d972657e51afa (diff)
parent6f518c687f743b68d3eeddedcf3d831aca20d4ec (diff)
downloadperlweeklychallenge-club-c804b128cf740d95b244cd3fe15e86d0820ab51e.tar.gz
perlweeklychallenge-club-c804b128cf740d95b244cd3fe15e86d0820ab51e.tar.bz2
perlweeklychallenge-club-c804b128cf740d95b244cd3fe15e86d0820ab51e.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-030')
-rw-r--r--challenge-030/paulo-custodio/Makefile2
-rw-r--r--challenge-030/paulo-custodio/README1
-rw-r--r--challenge-030/paulo-custodio/perl/ch-1.pl18
-rw-r--r--challenge-030/paulo-custodio/perl/ch-2.pl26
-rw-r--r--challenge-030/paulo-custodio/python/ch-1.py16
-rw-r--r--challenge-030/paulo-custodio/python/ch-2.py19
-rw-r--r--challenge-030/paulo-custodio/t/test-1.yaml5
-rw-r--r--challenge-030/paulo-custodio/t/test-2.yaml12
8 files changed, 99 insertions, 0 deletions
diff --git a/challenge-030/paulo-custodio/Makefile b/challenge-030/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-030/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-030/paulo-custodio/README b/challenge-030/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-030/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-030/paulo-custodio/perl/ch-1.pl b/challenge-030/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..7160d8840b
--- /dev/null
+++ b/challenge-030/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+# 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 Modern::Perl;
+use DateTime;
+
+my @sunday_xmas;
+for my $year (2019..2100) {
+ my $date = DateTime->new(year=>$year, month=>12, day=>25);
+ push @sunday_xmas, $year if $date->day_of_week == 7;
+}
+
+say join(", ", @sunday_xmas);
diff --git a/challenge-030/paulo-custodio/perl/ch-2.pl b/challenge-030/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..974dca199a
--- /dev/null
+++ b/challenge-030/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+# 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 Modern::Perl;
+use List::Util 'sum';
+use List::MoreUtils 'any';
+
+my $sum = shift||12;
+
+for my $i (1..$sum) {
+ for my $j ($i+1..$sum) {
+ for my $k ($j+1..$sum) {
+ if (sum($i, $j, $k) == $sum) {
+ if (any {$_%2==0} $i, $j, $k) {
+ say "$i,$j,$k"
+ }
+ }
+ }
+ }
+}
diff --git a/challenge-030/paulo-custodio/python/ch-1.py b/challenge-030/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..4f15e8d7b5
--- /dev/null
+++ b/challenge-030/paulo-custodio/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/usr/bin/python3
+
+# Challenge 030
+#
+# Task #1
+# Write a script to list dates for Sunday Christmas between 2019 and 2100. For
+# example, 25 Dec 2022 is Sunday.
+
+import datetime
+
+sunday_xmas = []
+for year in range(2019, 2101):
+ dt = datetime.date(year, 12, 25)
+ if dt.isoweekday()==7:
+ sunday_xmas.append(year)
+print(*sunday_xmas, sep=", ")
diff --git a/challenge-030/paulo-custodio/python/ch-2.py b/challenge-030/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..29da0ffd41
--- /dev/null
+++ b/challenge-030/paulo-custodio/python/ch-2.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+# 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.
+
+import sys
+
+S = int(sys.argv[1])
+
+for i in range(1, S+1):
+ for j in range(i+1, S+1):
+ for k in range(j+1, S+1):
+ if sum([i, j, k]) == S:
+ if any([x%2==0 for x in [i, j, k]]):
+ print(f"{i},{j},{k}")
diff --git a/challenge-030/paulo-custodio/t/test-1.yaml b/challenge-030/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..679021db33
--- /dev/null
+++ b/challenge-030/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095
diff --git a/challenge-030/paulo-custodio/t/test-2.yaml b/challenge-030/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..b0782d35ac
--- /dev/null
+++ b/challenge-030/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,12 @@
+- setup:
+ cleanup:
+ args: 12
+ input:
+ output: |
+ 1,2,9
+ 1,3,8
+ 1,4,7
+ 1,5,6
+ 2,3,7
+ 2,4,6
+ 3,4,5