|
Web design and Programming Discuss website creation and other programming topics. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||
|
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 }
__________________
Delta Force 2 Enhanced Modding Site, new and improved with forum. |
#2
|
||
|
Permutations bring back nightmares... lol
__________________
True forgiveness comes not from those who pull the trigger, but from those who have |
#3
|
||
|
LoL, I enjoyed them at first, but now that we're working with them in probability, I'm not too fond of them.
__________________
Delta Force 2 Enhanced Modding Site, new and improved with forum. |
#4
|
||
|
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 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
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 |