Created
March 22, 2011 17:01
-
-
Save dbyrne/881580 to your computer and use it in GitHub Desktop.
Project Euler #5 - Scala
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
| 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