A while back on the TDAG list Bob Murdoch was trying to figure out Combinations in Delphi. I wrote this code for him and anyone else who is interested. Combination needs Factorial, and I decided to through Permutation (which also needs Factorial) in for good measure. I added an optimization in on Combination that requires an additional parameter (AStop) on Factorial. (Thanks to Brian Mayland for pointing out a bug in my optimization.) If you are calling factorial directly then just leave AStop as 0 [Zero]. If you wanted to you could have an overloaded version of Factorial instead of using a default parameter.
The code is available under MPL or LGPL.
No comments:
Post a Comment