rewrote algo for Pi calculation to use 'map' instead of 'for-yield'

This commit is contained in:
Jonas Bonér 2011-04-01 23:34:11 +02:00
parent 4ba2296c16
commit 03914a2b0f

View file

@ -74,8 +74,7 @@ object Pi {
// define the work
val algorithm = (i: Int) => {
val range = (i * nrOfElements) to ((i + 1) * nrOfElements - 1)
val results = for (j <- range) yield (4 * math.pow(-1, j) / (2 * j + 1))
results.sum
range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum
}
// message handler