diff options
| -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."; |
