Go Back   Novahq.net Forum > Computers > Web design and Programming

Web design and Programming Discuss website creation and other programming topics.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-03-2010, 12:19 PM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
C#: Factorials, Combinations, and Permutations Class

Code:
    // Class Name: Basic Counting Theory
    // Author: Bullet Magnet
    // Version: 1.0
    // Copyright: 2010 Bullet Magnet

    public class BasicCountingTheory
    {
        #region CaclulateFactorial
        // Factorial method
        // Accepts one parameter of type long
        public static long CalculateFactorial(long x)
        {
            long fact = 1; 
            long i = 1; // Lowest possible term in a factorial

            // Loop through each subsequent terms of x
            while (i <= x)
            {
                fact = fact * i; 
                i++;
            }
            return fact;
        }
        #endregion

        #region Permutation
        // This method calculates permutations, in which the order of a selection matters
        // Accepts 2 parameters for use in the main formula
        public static long Permutation(long a, long b)  
        {
            // Variable used to store result
            long result;
            // Main formula: (n!/((n-r)!))
            result = ((CalculateFactorial(a))/(CalculateFactorial(a-b)));

            return result;
        }
        #endregion

        #region Combination(long a, long b)
        // This method calclulates combinations, in which order of a selection doesn't matter
        public static long Combination(long a, long b)
        {
            // Variable used to store result
            long result;
            // Main formula: (n!/((n-r)!)r!)
            result = ((CalculateFactorial(a)) / ((CalculateFactorial(a - b) * CalculateFactorial(b))));

            return result;
        }
        #endregion
    }
Reply With Quote
  #2  
Old 09-10-2010, 09:43 AM
ShadowZ is offline ShadowZ
Chick Magnet(?)

Join Date: Jun 2009
Location: The "Mud Hole," USA
Posts: 295

Permutations bring back nightmares... lol
__________________
True forgiveness comes not from those who pull the trigger, but from those who have
Reply With Quote
  #3  
Old 09-13-2010, 12:10 AM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
LoL, I enjoyed them at first, but now that we're working with them in probability, I'm not too fond of them.
Reply With Quote
  #4  
Old 09-13-2010, 11:17 PM
ShadowZ is offline ShadowZ
Chick Magnet(?)

Join Date: Jun 2009
Location: The "Mud Hole," USA
Posts: 295

Yup, Probability gets very confusing if you try to skim over it... Lol
__________________
True forgiveness comes not from those who pull the trigger, but from those who have
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Project EDGE Sigs and Graphics 7 05-29-2007 09:13 AM
First Class Blonde bigsmellyfart Humor & Jokes 5 10-12-2006 09:08 PM
SYSDUMP Errors with certain Combinations DC_Scout_67 Delta Force 2 03-25-2006 10:38 PM
ediquette class Dragon-SC- Humor & Jokes 4 10-22-2005 04:17 PM


All times are GMT -5. The time now is 06:50 PM.




Powered by vBulletin®