I'm 4/6 for recursive solutions! And today's a dou...
# advent-of-code
e
k
We need persistent lists, that
pathToCom
function just hurts to think about!
e
How do you mean?
k
It's making a copy of the list on every recursion step, so that O(n^2) allocated memory and time just to build a list.
e
Copy code
private tailrec fun MutableList<String>.pathToCom(from: String) {
    val next = input[from] ?: return
    add(next)
    pathToCom(next)
}
Runs in almost half the time... from ~0.9ms to ~0.45ms.
🎉 2
n
👍 1