aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-02-13 04:49:51 +0000
committerGitHub <noreply@github.com>2023-02-13 04:49:51 +0000
commitbad641c8aed91af07c8cabc8667e8b0b1845103e (patch)
treedda83acc6cb818b8abc6e3b199e979f43a21e6ef
parentad9c3ff124f680e647b6314aef31bb7821832da1 (diff)
parent2172c8c0f6ec5faa8ac2f2dd99b1e91f5162878c (diff)
downloadperlweeklychallenge-club-bad641c8aed91af07c8cabc8667e8b0b1845103e.tar.gz
perlweeklychallenge-club-bad641c8aed91af07c8cabc8667e8b0b1845103e.tar.bz2
perlweeklychallenge-club-bad641c8aed91af07c8cabc8667e8b0b1845103e.zip
Merge pull request #7541 from carlos157oliveira/challenge-203
solution to challenge 203
-rw-r--r--challenge-203/carlos-oliveira/perl/ch-1.pl25
-rw-r--r--challenge-203/carlos-oliveira/perl/ch-2.pl29
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-203/carlos-oliveira/perl/ch-1.pl b/challenge-203/carlos-oliveira/perl/ch-1.pl
new file mode 100644
index 0000000000..18a3893ad2
--- /dev/null
+++ b/challenge-203/carlos-oliveira/perl/ch-1.pl
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use v5.36;
+
+use Test::More;
+
+sub count_special_quadruplets {
+ my $quadruplet_count = 0;
+ for my $a (0 .. $#_ - 3) {
+ for my $b ($a + 1 .. $#_ - 2) {
+ for my $c ($b + 1 .. $#_ - 1) {
+ for my $d ($c + 1 .. $#_) {
+ $quadruplet_count++ if $_[$a] + $_[$b] + $_[$c] == $_[$d];
+ }
+ }
+ }
+ }
+ return $quadruplet_count;
+}
+
+is count_special_quadruplets(1,2,3,6), 1;
+is count_special_quadruplets(1,1,1,3,5), 4;
+is count_special_quadruplets(3,3,6,4,5), 0;
+
+done_testing;
diff --git a/challenge-203/carlos-oliveira/perl/ch-2.pl b/challenge-203/carlos-oliveira/perl/ch-2.pl
new file mode 100644
index 0000000000..79c1347ccd
--- /dev/null
+++ b/challenge-203/carlos-oliveira/perl/ch-2.pl
@@ -0,0 +1,29 @@
+use v5.36;
+use strict;
+use warnings;
+
+use Const::Fast;
+
+sub copy_only_directories;
+
+sub copy_only_directories ($source, $target) {
+ opendir(my $dir, $source) or die "Can't open directory: $source";
+ while (my $entry = readdir $dir) {
+ const my $source_entry => "$source/$entry";
+ next unless -d $source_entry && $entry !~ /^[.]{1,2}$/;
+ const my $dest_entry => "$target/$entry";
+ mkdir $dest_entry or die "Can't create directory: $dest_entry";
+ copy_only_directories $source_entry, $dest_entry;
+ }
+ closedir $dir;
+}
+
+unless (@ARGV == 2) {
+ die "USAGE: $0 source/dir target/dir";
+}
+
+unless (-d $ARGV[1]) {
+ mkdir $ARGV[1] or die "Can't create directory: $ARGV[1]";
+}
+
+copy_only_directories $ARGV[0], $ARGV[1];