Created
July 9, 2013 16:43
-
-
Save mbc9news/5958992 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
object Euler_014 extends App { | |
def collatz(curNum:BigInt, times:Int = 1):Int = { | |
if(curNum equals 1) return times | |
if(curNum%2 equals 0) collatz(curNum/2, times+1) | |
else collatz(3*curNum+1, times+1) | |
} | |
val result = (1 to 1000000).map(collatz(_)) | |
println(result.indexOf(result.max)+1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment