Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Created May 7, 2017 06:43
Show Gist options
  • Save dgadiraju/cbe2b0d8a266716409d7b72578bcc5d6 to your computer and use it in GitHub Desktop.
Save dgadiraju/cbe2b0d8a266716409d7b72578bcc5d6 to your computer and use it in GitHub Desktop.
/**
* 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")
}
}
@jaiswalbit
Copy link

jaiswalbit commented May 11, 2017

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))

scala error - intellij - value not a member

Kindly help.

Regards,
Vishal.
[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment