Skip to content

Instantly share code, notes, and snippets.

@outsideris
Created July 14, 2013 01:57
Show Gist options
  • Save outsideris/5992902 to your computer and use it in GitHub Desktop.
Save outsideris/5992902 to your computer and use it in GitHub Desktop.
euler problem 14
import scala.annotation.tailrec
@tailrec
def loop(n: Long, count: Int = 0): Int = {
n match {
case 1 => count
case x if x % 2 == 0 => loop(x / 2, count + 1)
case x if x % 2 == 1 => loop(3 * x + 1, count + 1)
}
}
(for (
i <- 1 to 1000000
) yield (i, loop(i)) ).maxBy(_._2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment