diff options
Diffstat (limited to 'challenge-204/wlmb/perl/ch-1.pl')
| -rwxr-xr-x | challenge-204/wlmb/perl/ch-1.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-204/wlmb/perl/ch-1.pl b/challenge-204/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..66cc937e71 --- /dev/null +++ b/challenge-204/wlmb/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# Perl weekly challenge 204 +# Task 1: Monotonic Array +# +# See https://wlmb.github.io/2023/02/13/PWC204/#task-1-monotonic-array +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 N1 [N2...] + to test if the sequence N1 N2... is monotonic + FIN +my @orig=@ARGV; +my $current=shift; +my ($increasing, $decreasing); +for(@ARGV){ + $_>$current and $increasing=1; + $_<$current and $decreasing=1; + last if $increasing and $decreasing; # shortcut if non monotonic + $current=$_; +} +my ($result, $reason)= + $increasing && $decreasing?(0, "Non-monotonic"): + $increasing ?(1, "Non-decreasing"): + $decreasing ?(1, "Non-increasing"): + (1, "Constant"); +say join " ", @orig, "->", $result, $reason; |
