-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.kt
More file actions
35 lines (31 loc) · 815 Bytes
/
solution.kt
File metadata and controls
35 lines (31 loc) · 815 Bytes
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
fun main(args: Array<out String>) {
for (index in generateSequence(1, Int::inc)) {
val line = readLine()!!
if (line == "0") {
break
}
var isValid = true
var acceptable = "1"
var isLast2 = false
for (c in line) {
if (c !in acceptable) {
isValid = false
break
}
isLast2 = c == '2'
acceptable = when (c) {
'1', '3' -> "45"
'2' -> ""
'4', '6' -> "23"
'5', '7' -> "8"
'8' -> "67"
else -> return
}
}
if (isValid && isLast2) {
"VALID"
} else {
"NOT"
}.let { println("$index. $it") }
}
}