Alex Wilson
05/08/2020, 12:16 AMfun main() {
val list = """
a,234,97654/
b,23,ABC,
b,44235,203
a,234,97654/
b,23,ABC
b,44235,203
49,234
39,9291
""".trimIndent().split("\n")
var total = mutableListOf<String>()
for ((index, value) in list.withIndex()){
var sb = StringBuilder()
var nextIndex = index
if(value.startsWith("a") && value.endsWith("/")) {
sb.append(value)
while(list[nextIndex + 1].startsWith("b")) {
sb.append(list[nextIndex + 1])
nextIndex++
}
total.add(sb.toString())
}
}
}
Jakub Pi
05/08/2020, 1:00 AMfold
, takeWhile
and flatten
though there is more than one valid approach.
This problem is a little tricky since your handling is context sensitive.Alex Wilson
05/08/2020, 1:02 AMJakub Pi
05/08/2020, 3:10 AMJakub Pi
05/08/2020, 3:11 AMJakub Pi
05/08/2020, 3:25 AMJakub Pi
05/08/2020, 3:29 AMMichael de Kaste
05/08/2020, 7:35 AMMichael de Kaste
05/08/2020, 8:07 AMAlex Wilson
05/08/2020, 11:43 AMJakub Pi
05/08/2020, 2:12 PMJakub Pi
05/08/2020, 2:15 PMAlex Wilson
05/08/2020, 4:12 PM