No Matter How You Slice It — Day 3, Part 1
# advent-of-code
k
No Matter How You Slice It — Day 3, Part 1
woooow I'm spending way too long on just the input.
I figured that the input is pretty regular, I'd use a regular expression, just name some capture groups and shove them into a data class...
but apparently named capture groups are a thing in Java, where they didn't really work until Java 8 and then kinda broke in Kotlin for Java 9: https://youtrack.jetbrains.com/issue/KT-20865
tagged as fixed in Kotlin 1.3.20? 🤞
t
I managed to get it done with a regex just using capture groups (without names), destructuring, and creating my data class.
It feels weird doing this in the middle of the night, instead of first thing, but I'm traveling and can't sleep and am alone so I might as well code. 🙂
Part was is so nice and clean for me, part two is fine, but side-effecty. 🙂
Alright, I'm exhausted. I've been up for 22 hrs, have been traveling, and need to work early this morning. G'night all! 🙂
😴 1
j
I skipped regular expression parsing and went crude, using the ability to pass multiple delimiters to `CharSequence.split()`:
Copy code
line.split("#", "@", ",", ":", "x")
   .filter { it.isNotEmpty() }
   .map { it.trim().toInt() }
🤔 1
t
Oh that’s neat. Didn’t even think of that one!
w
i did something similar to @Joris PZ
Copy code
fun parseClaim(input: String): Claim {
    val tokens = input
            .split('#', ':', ',', 'x', ':', '@')
            .map(String::trim)
    return Claim(id = tokens[1],
            xOffset = tokens[2].toInt(),
            yOffset = tokens[3].toInt(),
            width = tokens[4].toInt(),
            height = tokens[5].toInt())
}
part 1 was a lot harder for me than part 2 lol. part 2 took me like 5 min. my part 2 also performs waaaaay better
263ms / 12ms