-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.kt
35 lines (33 loc) · 983 Bytes
/
solution.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
enum class Direction {
Ascending,
Descending,
Mixed,
Unknown
}
fun main(args: Array<out String>) {
val numbers = readLine()!!.split(" ").map { it.toInt() }
var direction = Direction.Unknown
for ((prev, curr) in numbers.windowed(2)) {
if (prev < curr) {
if (direction == Direction.Unknown || direction == Direction.Ascending) {
direction = Direction.Ascending
} else {
direction = Direction.Mixed
break
}
} else {
if (direction == Direction.Unknown || direction == Direction.Descending) {
direction = Direction.Descending
} else {
direction = Direction.Mixed
break
}
}
}
when (direction) {
Direction.Ascending -> "ascending"
Direction.Descending -> "descending"
Direction.Mixed -> "mixed"
else -> ""
}.let(::println)
}