From 246354dbd869c27be6e223353d1448dce39d16d1 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Sat, 15 Mar 2014 10:07:21 +0100 Subject: [PATCH] Add Probability class in math\statistics package --- src/math/statistics/Probability.java | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/math/statistics/Probability.java diff --git a/src/math/statistics/Probability.java b/src/math/statistics/Probability.java new file mode 100644 index 0000000..ac726db --- /dev/null +++ b/src/math/statistics/Probability.java @@ -0,0 +1,97 @@ +package math.statistics; + +import math.Maths; + + +public class Probability { + + /** + * Permutation. n!. e. g. n = 6 balls with different properties. + * Number of arrangements. + * @param n total number of things + * @return permutation + * @see Maths#factorial(long) + */ + public static long permutation(int n){ + return Maths.factorial((long)n); + } + + /** + * Permutation. n!/k!. e. g. n = 6 balls, k = 3 balls of same property (same color), n-k with different properties. + * Number of arrangements. + * @param n total number of things + * @param k number of same properties + * @return permutation + */ + public static long permutation(int n, int k){ + return permutation(n)/permutation(k); + } + + /** + * Permutation. n!/k!. + * e. g. n = 6 balls, k = [3 balls of one same property (black), 3 balls of other same property], n-k with different properties. + * Number of arrangements. + * @param n total number of things + * @param ki multiple number of same properties + * @return permutation + */ + public static long permutation(int n, int... ki){ + int i; + long k = 1; + for(i=0; ik. + * Arrange and Pick. + * @param n total number of things + * @param k taken things + * @return variations with repetition + */ + public static long variationRepetition(int n, int k){ + return Maths.pow(n, k); + } + + public static void main(String[] args) { + } + +}