aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2023-02-06 22:38:08 -0500
committerDavid Ferrone <zapwai@gmail.com>2023-02-06 22:38:08 -0500
commit93b128e4276795b7579e936b006b640a9e1b3653 (patch)
treec998b68af748e6cd76d2b3eced9759064bc2ff3f
parentf92e84261b474f81c014f4982268d6e2797b66d9 (diff)
downloadperlweeklychallenge-club-93b128e4276795b7579e936b006b640a9e1b3653.tar.gz
perlweeklychallenge-club-93b128e4276795b7579e936b006b640a9e1b3653.tar.bz2
perlweeklychallenge-club-93b128e4276795b7579e936b006b640a9e1b3653.zip
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;
+ }
+ }
+}