Created
August 22, 2012 05:54
-
-
Save stingh711/3422686 to your computer and use it in GitHub Desktop.
Project euler problem 5 solution
This file contains hidden or 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 Issue5 { | |
| def gcd(a: Long, b: Long): Long = { | |
| if (b == 0) a else gcd(b, a % b) | |
| } | |
| def lcm(a: Long, b: Long) = { | |
| a * b / (gcd(a, b)) | |
| } | |
| def smallestLcm(l: List[Long]) = { | |
| l.foldLeft(1L)(lcm(_, _)) | |
| } | |
| def main(args: Array[String]) { | |
| println(smallestLcm((1L to 10L).toList)) | |
| println(smallestLcm((1L to 20L).toList)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment