Forked from gclaramunt/Sumatoria y Productoria.scala
Created
August 11, 2011 18:51
-
-
Save fogus/1140428 to your computer and use it in GitHub Desktop.
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
def ∑(r:Range)(f:Int =>Int)=r.reduceLeft(_+ f(_)) | |
def ∏(r:Range)(f:Int =>Int)=r.reduceLeft(_* f(_)) | |
// And now we can write: | |
val s= ∑(1 to 100)(x=>x^2) | |
val p= ∑(1 to 100 by 2)(x=>x^2) | |
val y= ∏(1 to 30 by 3)(_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment