Skip to content

Instantly share code, notes, and snippets.

@dbyrne
Created March 22, 2011 17:01
Show Gist options
  • Select an option

  • Save dbyrne/881580 to your computer and use it in GitHub Desktop.

Select an option

Save dbyrne/881580 to your computer and use it in GitHub Desktop.
Project Euler #5 - Scala
val divisors = List(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
def divisibleByAll(x:Int, divs:List[Int]):Boolean = divs match {
case Nil => true
case _ => if (x % divs.head == 0) {
return divisibleByAll(x, divs.tail)
} else {
return false
}
}
def smallestAnswer(y:Int):Int = {
if (divisibleByAll(y,divisors)) {
return y
} else {
return smallestAnswer(y+20)
}
}
smallestAnswer(40) ;returns 232792560
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment