Sign in to follow this  
Followers 0
Paulie

Combinations and Permutaions

5 posts in this topic

For use with my statistics class, I whipped up 3 functions for Combinations and Permutations

The Functions;

Func _nCr($n_Population, $n_Permutation)
    Local $top = _Factorial($n_Population)
    local $SubBottom1 = _Factorial($n_Permutation)
    local $SubBottom2 = _Factorial($n_Population-$n_Permutation)
    Local $Bottom = $SubBottom1*$SubBottom2
    Local $result = Round($top/$bottom,0)
    Return $result
EndFunc

Func _nPr($n_Population, $n_Permutation)
    local $top = _Factorial($n_Population)
    local $Bottom = _Factorial($n_Population-$n_Permutation)
    Local $result = $top/$bottom
    Return Round($top/$bottom,0)
EndFunc

Func _Factorial($n_Number)
    Local $result = 1
    For $i = $n_Number to 1 step -1
        $result = $result*$i
    Next
    Return $result
EndFuncoÝ÷ Ø ÄÅ©©æ®¶­s`£´÷rÖçFffW&VçB6WG2öbB7GVFVçG26â&R6÷6Vâg&öÒw&÷WöbSòæ÷FS¢÷&FW"FöW6âb33·BÖGFW"£´ç7vW# ¤×6t&÷ÂgV÷C¶ä7"vVâãÓR#ÓBgV÷C²Åöä7"RÃB £´÷rÖçv26âB7GVFVçG2g&öÒw&÷WöbR&RÆæVBWf÷"÷Föw&òæ÷FS¢÷&FW"ÖGFW'2£´ç7vW# ¤×6t&÷ÂgV÷C¶å"vVâãÓR#ÓBgV÷C²Åöå"RÃB

Unfortunately, for some reason (I believe it is a restriction in autoit) I am unable to produce and accurate Factorial (equal to the "!" in math) for any number greater than 20 :whistle:

anyway, just more math!

Share this post


Link to post
Share on other sites



Does anyone have an idea how to get around the problem with factorials over 20?

Share this post


Link to post
Share on other sites

Does anyone have an idea how to get around the problem with factorials over 20?

Hi Paulie,

this should fix your problem.

Func _Factorial($n_Number)
    Local $result = 1.0 ;<== my modification
    For $i = $n_Number to 1 step -1
        $result = $result*$i
    Next
    Return $result
EndFunc

Cubehead

Share this post


Link to post
Share on other sites

Awesome Paulie and Cubehead, this is just the solution I was looking for. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0