Skip to content

Instantly share code, notes, and snippets.

@p3t0r
Created December 30, 2008 07:33
Show Gist options
  • Save p3t0r/41546 to your computer and use it in GitHub Desktop.
Save p3t0r/41546 to your computer and use it in GitHub Desktop.
package euler14
object Main {
def isCollatzSerie(n:BigInt, numElements:BigInt):(BigInt, BigInt) = {
if(n <= 1)
(n, numElements)
else if(n%2 == 0)
isCollatzSerie(n >> 1, numElements + 1)
else
isCollatzSerie(n*3 + 1, numElements + 1)
}
def main(args: Array[String]) = {
var num = 999999
var max:BigInt = 0
var maxStart = 0
while(num > 1){
var res = isCollatzSerie(num,0)
if(res._1 == 1 && res._2 > max){
max = res._2
maxStart = num
println("new max " + max + " numbers for number " + maxStart)
}
num = num - 2
}
println("found max " + max + " numbers for number " + maxStart)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment