id summary reporter owner description type status priority milestone component version resolution keywords cc blockedby blocking
2851 dojo.math.combinations is correct but inefficient guest anonymous "Great work guys!
I just wanted to suggest an improvement to dojo.math.combinations that does less math:
public int combinations(final int n, final int r) {
if(n==0 || r==0) return 1;
var bigger;
var smaller;
if (r<(n-r)) {
bigger=n-r;
smaller=r;
} else {
bigger=r;
smaller=n-r;
}
var num=1;
for(var i=n;i>bigger;i--){ num *= i; }
return num/factorial(smaller);
}
This produces the same results but is faster and uses fewer factorial() calls.
Write if you want me to explain the math behind it: gborek@thetdgroup.com
-gmb
" enhancement closed high General 0.4.2 wontfix math combinations