I was playing around with trying the complete the Hofstadter-Conway $10,000 sequence task in Scala on Rosetta Code. I want to use as idiomatic Scala as possible, but I'm having trouble implementing the algorithm without using raw recursion, which normally one only would use as a last resort. Here is what I currently have:
object HofstadterConway {
def makeHCSequence(max: Int): Seq[Int] = {
def hc(v: Vector[Int], idx: Int): Vector[Int] = {
if (idx == (max + 1)) {
v.tail
} else if (idx <= 2) {
hc(v :+ 1, idx + 1)
} else {
hc (v :+ (v(v(idx - 1)) + v(idx - v(idx - 1))), idx + 1)
}
}
hc(Vector(), 0)
}
}
Is there a way to do this more idiomatically?