Copyright | Copyright (c) , Patrick Perry <patperry@stanford.edu> |
---|---|

License | BSD3 |

Maintainer | Patrick Perry <patperry@stanford.edu> |

Stability | experimental |

Safe Haskell | None |

Language | Haskell98 |

Immutable combinations.

- data Choose
- choose :: Int -> Int -> Choose
- listChoose :: Int -> Int -> [Int] -> Choose
- at :: Choose -> Int -> Int
- unsafeAt :: Choose -> Int -> Int
- possible :: Choose -> Int
- size :: Choose -> Int
- elems :: Choose -> [Int]
- complement :: Choose -> Choose
- complElems :: Choose -> [Int]
- next :: Choose -> Maybe Choose
- prev :: Choose -> Maybe Choose

# Combinations

The immutable combination data type. A way of representing `k`

unordered outcomes from `n`

possiblities. The possibilites are
represented as the indices `0, ..., n-1`

, and the outcomes are
given as a subset of size `k`

. The subset is stored with the indices
in ascending order.

# Creating combinations

choose :: Int -> Int -> Choose Source

`choose n k`

returns the first combination of `k`

outcomes from `n`

possibilites, namely the subset `{ 0, ..., k-1 }`

.

listChoose :: Int -> Int -> [Int] -> Choose Source

Construct a combination from a list of elements.
`listChoose n k is`

creates a combination of `k`

outcomes from `n`

possibilities initialized to have the `i`

th element equal to `is !! i`

.
For the combination to be valid, the elements must all be unique, they
must be in sorted order, and they all must be in the range `0 .. n-1`

.

# Accessing combination elements

at :: Choose -> Int -> Int Source

`at c i`

gets the value of the `i`

th element of the combination
`c`

. The index `i`

must be in the range `0..(k-1)`

, where `k`

is the
size of the combination.

# Combination properties

# Combination functions

complement :: Choose -> Choose Source

Get the inverse of a combination

complElems :: Choose -> [Int] Source

Get a list of the elements in the complement of a combination.
If the combination is a subset of `k`

outcomes from `n`

possibilities, then
the returned list will be sorted and of length `n-k`

.