Created
December 30, 2008 07:33
-
-
Save p3t0r/41546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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