Michael Böiers
12/09/2021, 5:06 PMPaul Woitaschek
12/09/2021, 5:10 PMPaul Woitaschek
12/09/2021, 5:11 PMMichael Böiers
12/09/2021, 5:18 PMMichael Böiers
12/09/2021, 5:20 PMSimon Nyström
12/09/2021, 6:10 PMephemient
12/09/2021, 6:21 PMephemient
12/09/2021, 6:22 PMephemient
12/09/2021, 6:23 PMPaul Woitaschek
12/09/2021, 6:37 PMMichael Böiers
12/09/2021, 7:19 PMfun <V> List<V>.permutations(): List<List<V>> {
val result: MutableList<List<V>> = mutableListOf()
fun generate(k: Int, list: List<V>) {
// If only 1 element, just output the array
if (k == 1) {
result.add(list.toList())
return
}
for (i in 0 until k) {
generate(k - 1, list)
swap(list, if (k % 2 == 0) i else 0, k - 1)
}
}
generate(count(), toList())
return result
}
If I used that in a challenge, I feel like I would have to include (copy) it in the code presented as the solution. It feels kind of wrong to just import it and then pretend that my solution is 25 lines shorter 😉Marcin Wisniowski
12/09/2021, 8:04 PMPoint
class with a getAdjacentSides()
method to get adjacent points for the basin flood-fill. I would never use an external library, but anticipating what can be useful is part of the fun for me.ephemient
12/09/2021, 11:41 PMelizarov
12/10/2021, 4:57 AM