Created
May 10, 2011 10:54
-
-
Save vaclavbohac/964269 to your computer and use it in GitHub Desktop.
Primes in 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
| object Primes { | |
| def iterate(max: Int, callback: (Int) => Boolean) { | |
| for (i <- 1 to max) { | |
| if (callback(i)) { | |
| println(i) | |
| } | |
| } | |
| } | |
| def isPrime(number: Int) : Boolean = { | |
| for (i <- 2 to number - 1) { | |
| if (number % i == 0) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| def main(args: Array[String]) { | |
| val max = if (args.length > 0) args(0).toInt else 100 | |
| iterate(max, isPrime) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment