diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-21 18:31:30 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-21 18:31:30 +0000 |
| commit | 526df8fbd2625d575b6827dfd326a0d8804e24b3 (patch) | |
| tree | 51d7cc17705fbf755380aab64f0a677c858702b4 | |
| parent | 77460c019eebb24f018f2e8ed1e25ec1c56e2486 (diff) | |
| download | perlweeklychallenge-club-526df8fbd2625d575b6827dfd326a0d8804e24b3.tar.gz perlweeklychallenge-club-526df8fbd2625d575b6827dfd326a0d8804e24b3.tar.bz2 perlweeklychallenge-club-526df8fbd2625d575b6827dfd326a0d8804e24b3.zip | |
Add Perl solution to challenge 030
| -rw-r--r-- | challenge-030/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-030/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-030/paulo-custodio/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-030/paulo-custodio/perl/ch-2.pl | 26 | ||||
| -rw-r--r-- | challenge-030/paulo-custodio/t/test-1.yaml | 5 | ||||
| -rw-r--r-- | challenge-030/paulo-custodio/t/test-2.yaml | 12 |
6 files changed, 64 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/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 |
