# LibJAD Math Routines

## #include "jadmath.h"

## Overview

## Functions

### int** combinations(int* things, int num_el, int num, int* sz)

things | A list of integers. |

size | Size of the integer list. |

num | The number of elements desired in each combination. |

szout | This is an output variable. The number of combinations returned by the function. If set to NULL then this information is not returned. |

return | A list of combination lists. Each combination list is of size num and is NOT null terminated. The list of combinations itself is NULL terminated. |

This function computes the list of possible combinations of size num, for the list of integers provided to it. For instance, if the list contains the elements {10, 15, 23} and you want all combinations of size 2, then the returned list of lists would contains {{10,15},{10,23},{15,23},NULL}. Ordering of elements is not guarenteed.

The number of possible combinations grows very quickly, and for any significant combination of list size and desired elements per combination this function is likely to run out of memory and crash. Since the function itself is recursive, overflowing the stack is also a real possiability. This routine is not particularly efficent. Those with a serious need for this functionality should go read Knuth, Art of Programming, vol 3.

### int** permutations(int* list, int size, int* szout)

list | A list of integers. |

size | Size of the integer list. |

szout | This is an output variable. The number of permutations returned by the function. If set to NULL then this information is not returned. |

return | A list of permutation lists. .Each permutation list is of size size and is NOT null terminated. The list of permutations itself is NULL terminated |

This routine determine all possible permutations (orderings) for a list of integers. Ordering of elements in the returned list is not guaranteed.

The number of possible permutations grows very quickly, and for any significant list this function is likely to run out of memory and crash. Since the function itself is recursive, overflowing the stack is also a real possiability. This routine is not particularly efficent. Those with a serious need for this functionality should go read Knuth, Art of Programming, vol 3.

### int** permutations_nthings(int* list, int size, int num, int* szout)

list | A list of integers. |

size | Size of the integer list. |

num | Number of things in each permutation. |

szout | This is an output variable. The number of permutations returned by the function. If set to NULL then this information is not returned. |

return | A list of permutation lists. Each permutation list is of size size and is NOT null terminated. The list of permutations itself is NULL terminated. |

This routine determine all possible permutations (orderings) for a list of integers which contain only num items. Ordering of elements in the returned list is not guarenteed.

The number of possible permutations grows very quickly, and for any significant list this function is likely to run out of memory and crash. Since the function itself is recursive, overflowing the stack is also a real possiability. This routine is not particularly efficent. Those with a serious need for this functionality should go read Knuth, Art of Programming, vol 3.

### unsigned long factorial(unsigned short num)

num | The number to find the factorial for. |

return | The factorial of num. |

This is a simple recursive factorial routine, that does no error checking. Use with caution.