-
Notifications
You must be signed in to change notification settings - Fork 0
/
12a.kt
32 lines (31 loc) · 899 Bytes
/
12a.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
import kotlin.io.path.Path
import kotlin.io.path.readLines
import kotlin.math.*
fun main() {
val fileName = "12.in"
val tab = Path(fileName).readLines()
var result = 0
for (line in tab) {
val (puzzle, data) = line.split(" ")
val numbers = data.split(",").map { it.toInt() }
var questionMarks = 0
for (c in puzzle) if (c == '?') questionMarks++
for (mas in 0 until (1 shl questionMarks)) {
var current = ""
var questionNo = 0
for (c in puzzle) {
if (c != '?') current += c
else {
current += if (mas and (1 shl questionNo) != 0) '#' else '.'
questionNo++
}
}
val currentNumbers = mutableListOf<Int>()
for (block in current.split("\\.+".toRegex())) {
if (block != "") currentNumbers.add(block.length)
}
if (currentNumbers == numbers) result++
}
}
println(result)
}