AYA5D2EYQBZRYF5NI6H4WRLWIYLGWYV4BCU3LWLSJZSLZZMWUYDAC
fun filter(lines: List<List<Int>>, fn: KFunction1<List<Int>, Int>): List<Int> {
var index = 0
var candidates = lines
while (candidates.size > 1) {
candidates = candidates.filter { line -> line[index] == fn(candidates.column(index)) }
index++
}
return candidates.first()
}
fun filter(lines: List<List<Int>>, fn: KFunction1<List<Int>, Int>): List<Int> =
lines.indices.fold(lines) { candidates, index ->
if (candidates.size == 1) candidates
else candidates.filter { line -> line[index] == fn(candidates.column(index)) } }.single()