I usually write Euler solutions in Javascript. On problems requiring very large integers I have decided to learn Scala and take advantage of BigInt. I wrote a solution to Euler025, it works fast but reads like Javascript. Will the reviewer please comment on how to write this solution more idiomatically and, if you have a JS background, what resources did you find useful to learn syntax/best practices?
What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
Solution:
def e25(): Int = {
var a = BigInt("1")
var b = BigInt("1")
var index = 3
while(index > 0) {
val temp = a + b
if (temp.toString().length() > 999) {
return index
}
index += 1
a = b
b = temp
}
index
}
println(e25())