Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
object Binomial {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val n=5
|
||||
val k=3
|
||||
val result=binomialCoefficient(n,k)
|
||||
println("The Binomial Coefficient of %d and %d equals %d.".format(n, k, result))
|
||||
}
|
||||
|
||||
def binomialCoefficient(n:Int, k:Int)=fact(n) / (fact(k) * fact(n-k))
|
||||
def fact(n:Int):Int=if (n==0) 1 else n*fact(n-1)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
object Binomial extends App {
|
||||
def binomialCoefficient(n: Int, k: Int) =
|
||||
(BigInt(n - k + 1) to n).product /
|
||||
(BigInt(1) to k).product
|
||||
|
||||
val Array(n, k) = args.map(_.toInt)
|
||||
println("The Binomial Coefficient of %d and %d equals %,3d.".format(n, k, binomialCoefficient(n, k)))
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def bico(n: Long, k: Long): Long = (n, k) match {
|
||||
case (n, 0) => 1
|
||||
case (0, k) => 0
|
||||
case (n, k) => bico(n - 1, k - 1) + bico(n - 1, k)
|
||||
}
|
||||
println("bico(5,3) = " + bico(5, 3))
|
||||
Loading…
Add table
Add a link
Reference in a new issue