Is there a fancy collections helper method that ca...
# getting-started
a
Is there a fancy collections helper method that can help me do this sort of nested for loop when I need to consider each item in a list with the others?
Copy code
for (firstIndex in (0..inputs.size - 2)) {
        for (secondIndex in (firstIndex + 1..inputs.size - 1)) {
            val firstInput = inputs[firstIndex]
            val secondInput = inputs[secondIndex]
            ...
        }
    }
j
Are you doing the Advent of Code by any chance? This came up in today's puzzle. I did it like this, not sure if there's more elegant ways:
Copy code
val inputs = listOf(3, 4, 5)
inputs.forEachIndexed { index, n ->
    inputs.drop(index+1).forEach { m ->
        println(n * m)
   }
}
a
Yeah, that's where it came up. 🙂
r
I've written a
Combinatoric.kt
helper file with several functions because it comes up so often during AoC 😄
Btw, we're having discussions about Kotlin solutions over at #advent-of-code , come join us if you like!