Skip to content

Instantly share code, notes, and snippets.

@stingh711
Created August 22, 2012 05:54
Show Gist options
  • Select an option

  • Save stingh711/3422686 to your computer and use it in GitHub Desktop.

Select an option

Save stingh711/3422686 to your computer and use it in GitHub Desktop.
Project euler problem 5 solution
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