Day 1 is done!
# advent-of-code
t
Day 1 is done!
I went with a recursive solution to Part 2. I never use recursion it seems, unless I'm writing AoC solutions. 🙂
s
Nice! Recursion is definitely an AoC-only topic for me 😄 I seem to struggle more to intuit the behavior of a recursive function where a value is accumulated by passing it down through args as you did here.
I experimented with inline classes today and found them a bit more awkward than I was hoping: https://github.com/stkent/AdventOfCode2019/blob/master/day01/src/main/kotlin/Main.kt
Good opportunity to break out
coerceAtLeast
tho!
😮 1
t
Oh I didn't know about
coerceAtLeast
! That's cool.
🎉 3
Yeah, I wish inline classes were a bit more useful. I like how they implemented unsigned ints with them, but I feel like unless I can validate the underlying they would be more useful.
k
Why not use the return as the carry?
Copy code
private fun Int.fuelWithFuel(): Int =
        if (this < 7) {
            0
        } else {
            val fuel = this / 3 - 2
            fuel + fuel.fuelWithFuel()
        }
(this isn't tail recursive any more but you weren't using that anyway)
j
Also used recursion to finish part 2. But I already have used recursion in production project (yeah it's possible :p). Mostly for iterate over sub folders or tree hierarchy.
♻️ 1
t
Nice! I like recursion, but my work (back end for a financial services company) doesn't really call for it unfortunately. I DO get to write Kotlin though, so there's that. 😄
😄 3
Yeah, Karel, that's a really great point. I didn't really need the carry I guess. Good call.
Thanks again @karelpeeters - I published an update and credited you. 🙂
👍 1
s
Best part of this channel is seeing all this learning/tweaking!
t
Yeah, exactly. I learn something every day.
s
+1
s
I used a
fold
for the first part, and a
do...while
loop for the second. I can't help but think there's a more... kotlin-y solution?
k
You can force something with
generateSequence
but I couldn't find anything that was actually better.