diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-05-02 10:15:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-02 10:15:35 +0100 |
| commit | 44a70601a2b5169986d672a0b0f7b66b5c6c7fb1 (patch) | |
| tree | 88e76f69106d3b1d93465b1d6f8b11e23f972774 | |
| parent | f6c84eff9aa4e78b93dbd85cbda20231f6a05f4b (diff) | |
| parent | 19091e77f2aec8c216d330f6fa3ae967ab2b00bf (diff) | |
| download | perlweeklychallenge-club-44a70601a2b5169986d672a0b0f7b66b5c6c7fb1.tar.gz perlweeklychallenge-club-44a70601a2b5169986d672a0b0f7b66b5c6c7fb1.tar.bz2 perlweeklychallenge-club-44a70601a2b5169986d672a0b0f7b66b5c6c7fb1.zip | |
Merge pull request #8003 from zapwai/branch-for-215
Week 215
| -rw-r--r-- | challenge-215/zapwai/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-215/zapwai/perl/ch-2.pl | 39 |
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-215/zapwai/perl/ch-1.pl b/challenge-215/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..4dee7fa3fc --- /dev/null +++ b/challenge-215/zapwai/perl/ch-1.pl @@ -0,0 +1,19 @@ +use v5.30.0; +my @words = ('abc', 'xyz', 'cab'); +my $count = 0; +my $output; +say "Input: \@words = @words"; +print "Output: "; +is_alph($_) foreach (@words); +say $count; +say $output . "can be removed." if ($output); +sub is_alph { + my $word = shift; + my @let = split("",$word); + foreach (0 .. $#let - 1) { + if ($let[$_] gt $let[$_ + 1]) { + $count++ ; + $output .= $word . " "; + } + } +} diff --git a/challenge-215/zapwai/perl/ch-2.pl b/challenge-215/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..4b1ec36e45 --- /dev/null +++ b/challenge-215/zapwai/perl/ch-2.pl @@ -0,0 +1,39 @@ +use v5.30.0; +my @numbers = (1,0,0,0,1); +my $count = 1; +say "Input: \@numbers = (" . join(",", @numbers) . "), \$count = $count"; +print "Output: "; +sub spaces { + my $n = shift; + return 0 if ($n < 0); + if ($n % 2 == 0) { + ($n - 2) / 2 + } else { + ($n - 1) / 2 + } +} + +my $land; +my $water; +my $length = 0; +my $total; +foreach (0 .. $#numbers) { + if ($numbers[$_] != '0') { + $land = 1; + if ($water) { + $total += spaces($length); + $water = 0; + } + + } else { + $length++; + if ($land) { + $land = 0; + $water = 1; + } + } +} + +my $ans = ($count <= $total) || 0; +say $ans; +say "There is room for $total placements."; |
