セイロン、86バイト
Object m(Integer+l)=>let(c=l.paired.map(([x,y])=>x<=>y))[if(!smaller in c)equal in c];
関数は、パラメータとして入力を受け取り、そして0または1ブール値のタプルを返す- [false]
するためのモノトーンは厳密に減少、[true]
のためにモノトーンの非増加が、厳密に減少していない、と[]
のために上記のなし。
次のように使用できます。
shared void run() {
print("Monotone strictly decreasing:");
print(m(7, 5, 4, 3, 1));
print(m(42, 41));
print(m(5));
print("Monotone non-increasing, but not strictly decreasing:");
print(m(27, 19, 19, 10, 3));
print(m(6, 4, 2, 2, 2));
print(m(9, 9, 9, 9));
print("None of the above:");
print(m(1, 2, 3, 2));
print(m(10, 9, 8, 7, 12));
print(m(4, 6, 4, 4, 2));
}
出力:
Monotone strictly decreasing:
[false]
[false]
[false]
Monotone non-increasing, but not strictly decreasing:
[true]
[true]
[true]
None of the above:
[]
[]
[]
無償のコメント付きバージョン:
// Let's decrease the monotony!
//
// Question: http://codegolf.stackexchange.com/q/101036/2338
// My Answer: http://codegolf.stackexchange.com/a/101309/2338
// Define a function which takes a non-empty list `l` of Integers)
// (which arrive as a tuple) and returns an Object (actually
// a `[Boolean*]`, but that is longer.)
Object m(Integer+ l) =>
// the let-clause declares a variable c, which is created by taking
// pairs of consecutive elements in the input, and then comparing
// them. This results in lists like those (for the example inputs):
// { larger, larger, larger, larger }
// { larger }
// {}
// { larger, equal, larger, larger }
// { larger, larger, equal, equal }
// { equal, equal, equal }
// { smaller, smaller, larger }
// { larger, larger, larger, smaller }
// { smaller, larger, equal, larger }
let (c = l.paired.map( ([x,y]) => x<=>y) )
// now we analyze c ...
// If it contains `smaller`, we have an non-decreasing sequence.
// We return `[]` in this case (an empty tuple).
// Otherwise we check whether `equal` is in the list, returning
// `[true]` (a non-strictly decreasing sequence) if so,
// and `[false]` (a strictly decreasing sequence) otherwise.
[if(!smaller in c) equal in c];