This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,6 @@
def factorial(n: Int)={
var res = 1
for(i <- 1 to n)
res *=i
res
}

View file

@ -0,0 +1 @@
def factorial(n: Int) = if(n == 0) 1 else n * factorial(n-1)

View file

@ -0,0 +1 @@
def factorial(n: Int) = (2 to n).foldLeft(1)(_*_)

View file

@ -0,0 +1,5 @@
// Note use of big integer support in this version
implicit def IntToFac(i : Int) = new {
def ! = (2 to i).foldLeft(BigInt(1))(_*_)
}

View file

@ -0,0 +1,10 @@
scala> implicit def IntToFac(i : Int) = new {
| def ! = (2 to i).foldLeft(BigInt(1))(_*_)
| }
IntToFac: (i: Int)java.lang.Object{def !: scala.math.BigInt}
scala> 20!
res0: scala.math.BigInt = 2432902008176640000
scala> 100!
res1: scala.math.BigInt = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000