Let's decrease the monotony
Perl 6, 17 bytes
{[>](@_)+[>=] @_}
- Monotone strictly decreasing:
2
- Monotone non-increasing:
1
- Other:
0
Expanded:
{ # bare block lambda with implicit parameter list 「@_」
[>]( @_ ) # reduce using 「&infix:« > »」
+
[>=] @_ # reduce using 「&infix:« >= »」
}
MATL, 10, 7 bytes
0hdX>ZS
Try it online! or verify all test cases!
3 bytes saved, thanks to @LuisMendo!
The outputs are
Strictly decreasing: -1
Non-increasing: 0
Other: 1
Explanation:
0 % Push a '0'
h % Join the 0 to the end of the input array.
d % Get consecutive differences
X> % Get the largest difference
ZS % Get its sign
% Implicitly print it
Mathematica, 22 bytes
Sign@*Max@*Differences
Unnamed function taking a list of numbers as input. Returns -1
if the list is strictly decreasing, 0
if it's nonincreasing but not strictly decreasing, and 1
if it's neither.
Pretty simple algorithm: take the differences of consecutive pairs, take the largest one, and take the sign of that largest one.
(I feel like there must exist some language in which this algorithm is 3 bytes....)
Regarding an array with a single entry: Differences
yields an empty list; Max
of an empty list gives -∞
(!); and Sign[-∞]
evaluates to -1
(!!). So it actually works on this corner case. Gotta love Mathematica sometimes. (Indeed, the function also correctly labels an empty list as strictly decreasing.)