<https://github.com/edgars-supe/advent-of-code/blo...
# advent-of-code
e
https://github.com/edgars-supe/advent-of-code/blob/master/src/main/kotlin/lv/esupe/aoc/year2019/Day8.kt Couldn't think of a way to optimize this more. But I'm glad it took me less time for both parts than it did to get a permutation generator working yesterday... (and I still haven't done part 2)
Going char by char (
(0 until 25*6)
) and taking the first non-
2
from the layers works twice as fast, give or take, but isn't all that readable.
k
Oh wow, didn't know about
asString
, very neat. You could replace
fold
with
joinStoString
I think.
e
asString()
is an extension I wrote. 🙂
Copy code
fun List<Char>.asString(): String = joinToString(separator = "")
😃 1
Good point on the fold!
Hmm,
joinToString()
isn't any faster, but more readable, I'd say. 🙂
k
Yeah no it should be about the same since it just uses the same stringbuilder inside.