Skip to content

Instantly share code, notes, and snippets.

@mbc9news
Created July 9, 2013 16:43
Show Gist options
  • Save mbc9news/5958992 to your computer and use it in GitHub Desktop.
Save mbc9news/5958992 to your computer and use it in GitHub Desktop.
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