diff options
| -rw-r--r-- | challenge-325/zapwai/ch-1.pl | 28 | ||||
| -rw-r--r-- | challenge-325/zapwai/ch-2.pl | 21 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-325/zapwai/ch-1.pl b/challenge-325/zapwai/ch-1.pl new file mode 100644 index 0000000000..0d725ac4d8 --- /dev/null +++ b/challenge-325/zapwai/ch-1.pl @@ -0,0 +1,28 @@ +use v5.38; +sub proc(@binary) { + say "Input: @binary"; + my $max = 0; + my $run = 0; + my $flag = 0; + for my $i (0 .. $#binary) { + if ($binary[$i] == 1) { + if ($flag == 0) { + $run = 1; + $flag = 1; + } else { + $run++; + } + } else { + $flag = 0; + } + $max = $run if ($max < $run); + } + say "Output: $max"; +} + +my @binary = (0, 1, 1, 0, 1, 1, 1); +proc(@binary); +@binary = (0,0,0,0); +proc(@binary); +@binary = (1,0,1,0,1,1); +proc(@binary); diff --git a/challenge-325/zapwai/ch-2.pl b/challenge-325/zapwai/ch-2.pl new file mode 100644 index 0000000000..ffb4f6db30 --- /dev/null +++ b/challenge-325/zapwai/ch-2.pl @@ -0,0 +1,21 @@ +use v5.38; +sub proc(@prices) { + say "Input: @prices"; + for my $i (0 .. $#prices) { + my $price = $prices[$i]; + for my $j ($i + 1 .. $#prices) { + if ($prices[$j] <= $price) { + $prices[$i] -= $prices[$j]; + last; + } + } + } + say "Output: @prices"; +} + +my @prices = (8, 4, 6, 2, 3); +proc(@prices); +@prices = (1,2,3,4,5); +proc(@prices); +@prices = (7,1,1,5); +proc(@prices); |
