Created
July 14, 2013 01:57
-
-
Save outsideris/5992902 to your computer and use it in GitHub Desktop.
euler problem 14
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
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