Skip to content

Instantly share code, notes, and snippets.

@daclouds
Last active December 19, 2015 17:39
Show Gist options
  • Save daclouds/2597eecb6f13925bb2d8 to your computer and use it in GitHub Desktop.
Save daclouds/2597eecb6f13925bb2d8 to your computer and use it in GitHub Desktop.
object Euler14 extends App {
def collatzConjecture(n: Long, c: Int = 1): Int = n match {
case 1 => c
case n if n % 2 == 0 => collatzConjecture(n / 2, c + 1)
case _ => collatzConjecture(3 * n + 1, c + 1)
}
}
println( (1 to 1000000).map(collatzConjecture(_)).zipWithIndex.max._2 + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment