diff options
| author | CY Fung <fungcheokyin@gmail.com> | 2022-09-19 02:00:33 +0800 |
|---|---|---|
| committer | CY Fung <fungcheokyin@gmail.com> | 2022-09-19 02:00:33 +0800 |
| commit | e97bacd5b710e12b8f665df84e297ba3aafde668 (patch) | |
| tree | b70ec58974aa9f56ea42e8da0b65c60c88ff06ee | |
| parent | 20f74e0dccc5c996dfee674f0efa307bfe49d8f3 (diff) | |
| download | perlweeklychallenge-club-e97bacd5b710e12b8f665df84e297ba3aafde668.tar.gz perlweeklychallenge-club-e97bacd5b710e12b8f665df84e297ba3aafde668.tar.bz2 perlweeklychallenge-club-e97bacd5b710e12b8f665df84e297ba3aafde668.zip | |
Week 182
| -rw-r--r-- | challenge-182/perl/ch-1.pl | 3 | ||||
| -rw-r--r-- | challenge-182/perl/ch-2.pl | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-182/perl/ch-1.pl b/challenge-182/perl/ch-1.pl new file mode 100644 index 0000000000..5b9ba1b157 --- /dev/null +++ b/challenge-182/perl/ch-1.pl @@ -0,0 +1,3 @@ +chomp $_; @arr = split /\D+/, $_; $m = 0; for (1..$#arr) {$m = $_ if $arr[$_] > $arr[$m];}; say $m; + +# perl -nE '...' diff --git a/challenge-182/perl/ch-2.pl b/challenge-182/perl/ch-2.pl new file mode 100644 index 0000000000..3f7571ae09 --- /dev/null +++ b/challenge-182/perl/ch-2.pl @@ -0,0 +1,30 @@ +# The Weekly Challenge 182 +# Task 2 Common Path +use v5.30.0; +use List::Util qw/all/; + +my @files = qw{ + /a/b/c/d/x.pl + /a/b/c/1/x.pl + /a/b/c/d/e/2/x.pl + /a/b/c/d/3/x.pl + /a/b/c/4/x.pl + /a/b/c/d/5/x.pl +}; + +my @arr; +my $i = 0; + +push @arr, [split "/", $_] foreach @files; + +my $a = shift @arr; + +while (defined($a->[$i]) && all {$_->[$i] eq $a->[$i]} @arr) { + $i++; + last if $a->[$i] =~ /\./; +} + +$i--; + +say $i > 0 ? (join "/", $a->@[0..$i]): "/"; + |
