Never seen an issue like this before. ```fun a(n: ...
# announcements
s
Never seen an issue like this before.
Copy code
fun a(n: Int)=if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
results in this error
Copy code
Error:(107, 46) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
on the last recursive part. I'm not sure how to resolve it, i've tried casting n to Int there, but it does nothing...
c
It’s because the function is declared as an expression, but it cannot resolve the expression without knowing the type of the function. You will have to move the expression into the function body
Copy code
fun a(n: Int): Int {
    return if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
}
s
Ah, Ok, so I can resolve it just by specifying a function type.
fun a(n: Int):Int=if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
works.
☝️ 1
thank you.
k
Also #C87V9MQFK exists, in case you need any more help with the other days
s
@Kroppeb thank you! I'm actually on day 7 but I run code golf competitions at my work and we're doing the first two days of Advent of code as a comp.
I'm actually doing AOC in Ruby and elixir but was doing the code golf in Ruby and kotlin. Lol