실론, 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];