Last active
December 1, 2016 03:28
-
-
Save lykkin/53df1cbd29ed8692ac18b28ace451d79 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
function fact(n) { | |
var res = 1 | |
for (var i = 1; i <= n; i++) { | |
res *= i | |
} | |
return res | |
} | |
function choose(n, k) { | |
return fact(n)/(fact(k) * fact(n - k)) | |
} | |
// out of n distinguishable choices, we have a subset of k elements | |
// this returns the probability of getting at least one of the k elements when choosing groups of j | |
function probWantedSubset(n, k, j) { | |
var res = 0 | |
for (var i = 0; i < Math.min(j, k); i++) { | |
res += choose(k, j-i)*choose(n-k, i) | |
} | |
res /= choose(n, k) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment