// the math formula (in my dialect): x = n! / ((n-r)!r!)
// finds factorial of a number
function fac(x){
var done = x;
while(x > 1) done *= --x;
return done;
}
// finds combinations given n = total number of options, and r = slots available to be filled with options.
function combo(n, r){
return fac(n) / (fac(n-r) * fac(r));
}
console.log("Combinations for 3 elected positions, with 6 candidates = " + combo(6, 3));
Sunday, April 16, 2023
Coding Challenge #53 Combinations
Subscribe to:
Post Comments (Atom)
Coding Challenge #54 C++ int to std::string (no stringstream or to_string())
Gets a string from an integer (ejemplo gratis: 123 -> "123") Wanted to come up with my own function for this like 10 years ago ...
-
I NEEDS MY JAVASCRIPT PLEASE :) Open txtcode .txt Save as .gct Please click the blue cheat code title to activate it, a...
-
Naruto Personality Quiz Please enable javascript ☯ Which Naruto Character Are You?
-
Useful for extensions that want to prevent event listeners from being attached or modify prototypes or functions, generally to defeat click...
No comments:
Post a Comment