Created
May 7, 2017 06:43
-
-
Save dgadiraju/cbe2b0d8a266716409d7b72578bcc5d6 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
/** | |
* Created by itversity on 07/05/17. | |
*/ | |
object combination { | |
def nCr(n: Int, r: Int) = { | |
def fact(i: Int) = { | |
var res = 1 | |
for(e <- i to 1 by -1) | |
res = res * e | |
res | |
} | |
fact(n)/(fact(n-r) * fact(r)) | |
} | |
def main(args: Array[String]): Unit = { | |
val n = args(0).toInt | |
val r = args(1).toInt | |
val c = nCr(n, r) | |
println("There are " + c + " combinations of " + r + " in " + n + " elements") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I tried to execute the same code on IntelliJ installed locally on my system. Got the below error in the line "fact(n)/(fact(n-r) * fact(r))"
Error:(11, 13) value / is not a member of Unit
fact(n)/(fact(r) * fact(n-r))
Error:(11, 23) value * is not a member of Unit
fact(n)/(fact(r) * fact(n-r))
Kindly help.
Regards,
Vishal.
[email protected]