A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: combination calculator

  1. #1
    Member
    Join Date
    Feb 2008
    Location
    Turkey...Istanbul
    Posts
    83

    combination calculator

    Hi,
    I am tring to create a simple calculator which will give me the result of combination of the number ı input via input boxes..
    for example (49-6)! output is 13.983.816 .Suppose that I have got 1 winning 6 ticket, how many winning 5s and how many winning 4s .have I got...?
    I have this link but it is not enough.
    http://www.easycalculation.com/stati...ombination.php
    thanks

  2. #2
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    Here is how to calculate combinations :
    You shouldnt have used the ! symbol in your example because it means factorial. For example, 5! = 1*2*3*4*5 = 120
    Now onto the main topic, the formula that will calculate C(b - a) is b! / (a! * (b-a)!). For example, C(49, 6) = 49! / (6! * 43!)
    Action script :
    code:

    function fact (a : Number) {
    return (a <= 0 ? 1 : a * fact (a - 1)); //It makes no sense for a to be < 0 but returning 1 is better than an infinite loop.
    }
    function combinations (a : Number, b : Number) {
    return (fact(b)) / (fact(a) * fact(b-a));
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center