rewrote algo for Pi calculation to use 'map' instead of 'for-yield'
This commit is contained in:
parent
4ba2296c16
commit
03914a2b0f
1 changed files with 1 additions and 2 deletions
|
|
@ -74,8 +74,7 @@ object Pi {
|
||||||
// define the work
|
// define the work
|
||||||
val algorithm = (i: Int) => {
|
val algorithm = (i: Int) => {
|
||||||
val range = (i * nrOfElements) to ((i + 1) * nrOfElements - 1)
|
val range = (i * nrOfElements) to ((i + 1) * nrOfElements - 1)
|
||||||
val results = for (j <- range) yield (4 * math.pow(-1, j) / (2 * j + 1))
|
range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum
|
||||||
results.sum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// message handler
|
// message handler
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue