aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-02-13 04:43:22 +0000
committerGitHub <noreply@github.com>2023-02-13 04:43:22 +0000
commit3ffc6f50179eddf1fe1f8cd0c9513de8ee3b29d5 (patch)
tree1f915de51801befbbe58b86f75b9e8bda581d448
parent46924dcca212f30aa726a492dfa72f9fab740708 (diff)
parent93b128e4276795b7579e936b006b640a9e1b3653 (diff)
downloadperlweeklychallenge-club-3ffc6f50179eddf1fe1f8cd0c9513de8ee3b29d5.tar.gz
perlweeklychallenge-club-3ffc6f50179eddf1fe1f8cd0c9513de8ee3b29d5.tar.bz2
perlweeklychallenge-club-3ffc6f50179eddf1fe1f8cd0c9513de8ee3b29d5.zip
Merge pull request #7538 from zapwai/branch-for-203
Week 203
-rw-r--r--challenge-203/zapwai/perl/ch-1.pl23
-rw-r--r--challenge-203/zapwai/perl/ch-2.pl33
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-203/zapwai/perl/ch-1.pl b/challenge-203/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..fe6eefcd89
--- /dev/null
+++ b/challenge-203/zapwai/perl/ch-1.pl
@@ -0,0 +1,23 @@
+use v5.30.0;
+my @array = (1,2,3,6);
+#my @array = (1,1,1,3,5);
+#my @array = (3,3,6,4,5);
+my $str;
+my $cnt;
+for my $a (0 .. $#array - 3) {
+ for my $b ($a + 1 .. $#array - 2) {
+ for my $c ($b + 1 .. $#array - 1) {
+ for my $d ($c + 1 .. $#array) {
+ my $sum = $array[$a] + $array[$b] + $array[$c];
+ if ($sum == $array[$d]) {
+ $cnt++ ;
+ $str .= "\$array[$a] + \$array[$b] + \$array[$c] == \$array[$d]\n";
+ }
+ }
+ }
+ }
+}
+say "Input: \@array = (".join(",",@array).")";
+$cnt = 0 unless ($cnt);
+say "Output: $cnt";
+print $str;
diff --git a/challenge-203/zapwai/perl/ch-2.pl b/challenge-203/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..f762a169fe
--- /dev/null
+++ b/challenge-203/zapwai/perl/ch-2.pl
@@ -0,0 +1,33 @@
+use v5.30.0;
+my $source = '/a/b/c/';
+my $target = '/x/y/';
+
+opendir my $dh, $source or die "$!";
+my @files = readdir $dh;
+closedir $dh;
+my @dirs;
+foreach (@files) {
+ next if (($_ eq ".") or ($_ eq ".."));
+ push @dirs, $_ if (-d $source.$_);
+}
+for (@dirs) {
+ #mkdir $target.$_;
+ say $target.$_;
+ proc($_);
+}
+
+sub proc {
+ my $wd = shift;
+ opendir my $dh, $source.$wd or die "$!";
+ my @files = readdir $dh;
+ closedir $dh;
+ foreach (@files) {
+ my $dir = "$wd/$_";
+ next if (($_ eq ".") or ($_ eq ".."));
+ if (-d $source.$dir) {
+ push @dirs, $dir;
+# mkdir $target.$dir;
+ say $target.$dir;
+ }
+ }
+}