metal-pony / bucket

haz bucket
0 stars 0 forks source link

Math utilities #11

Open metal-pony opened 2 years ago

metal-pony commented 2 years ago

Implement the following:


// TODO Returns n!. Throw exception if n! overflows Integer.MAX_VALUE.
public static int factorial(int n);

// TODO Returns n!. Throw exception if n! overflows Long.MAX_VALUE.
public static long factorial(long n);

// Returns an array containing every permutation of the given items.
public static <T extends List<T>> T[] permutations(List<T> items);

// Returns an array containing every permutation of the given items.
public static int[][] permutations(int[] items);

// Calculates "n choose k". This will probably require constraints to ensure calculation does not overflow.
public static int nChooseK(int n, int k);

// Returns an array containing every combination of 'k' items.
// Similar to above, this will probably require constraints or some mechanism to ensure calculation does not overflow.
public static <T extends List<T>> T[] combinations(List<T> items, int k);

// Returns an array containing every combination of 'k' items.
// Similar to above, this will probably require constraints or some mechanism to ensure calculation does not overflow.
public static int[][] combinations(int[] items, int k);
metal-pony commented 2 years ago

++ Repeat permutations and combinations methods for String

metal-pony commented 2 years ago

Also include some simple stats functions (mean/average (optional interquartile), median, variance, std dev)

public static float mean(int... values);
// Repeat for other types + Lists.

public static float mean(int... values, boolean interquartile);
// Override of above, also repeat for all implemented mean().

public static int median(int... values);

public static float variance(int... values);
// Repeat

public static float stddev(int... values);
// Repeat, is just java.lang.Math.sqrt(variance(values))
metal-pony commented 2 years ago

Mostly closed by sparklicorn/utility#23 Still would like nChooseK methods and tests before closing this.