Factorials, Permutations, Combinations





4
Date Submitted Mon. Apr. 17th, 2006 1:04 AM
Revision 1 of 4
Beginner Utsawin
Tags "ASP.NET 2.0" | combinations | factorials | math | permutations
Comments 3 comments
Go easy on me, my first snippet - plus I am new to VB.NET 2.0... with only basic knowledge of classic VB... Just want to mention that the Permutations function is not actually mine - found it online... (credit where credit's due)

Fairly simple stuff, but had me pulling my hair out - Even Excel has a COMBI function out of the box!
Visual Basic

'***** Factorial / Permutations / & Finally Combinations *****
    Public Function Factorial(ByVal factor As Double) As Double
        If factor = 0 Then
            Factorial = 1
        Else
            Factorial = factor * Factorial(factor - 1)
        End If
        Exit Function

        Return (Factorial)
    End Function

    Public Function Permutations(ByVal a As Double, ByVal b As Double) As Double
        '               a!()
        'a_P_b = -------- 
        '             (a - b)!

        Permutations = Factorial(a) / Factorial(a - b)

        Return (Permutations)
    End Function

    Public Function Combinations(ByVal a As Double, ByVal b As Integer) As Integer
        '             a_P_b       
        'a_C_b = -------- 
        '                 b!     
        Combinations = Permutations(a, b) / Factorial(b)
    End Function

 

Jules Honour

..:: It's better to look stupid, than open your mouth and remove all doubt ::..

Comments

Comments Oops...
Sat. Apr. 22nd, 2006 11:30 AM    Beginner Utsawin
Comments I think somethig went wrong?
Mon. Apr. 17th, 2006 2:52 PM    Syntax Master dannyboy
Comments Where's the snippet?
Mon. Apr. 17th, 2006 12:49 PM    Coder mattrmiller

Voting

Votes Down