Liking cljdoc? Tell your friends :D

sicmutils.util.permute

Utilities for generating permutations of sequences.

Utilities for generating permutations of sequences.
raw docstring

cartesian-productclj/s

(cartesian-product colls)

Accepts a sequence of collections colls and returns a lazy sequence of the cartesian product of all collections.

The cartesian product of N collections is a sequences of sequences, each N long, of every possible way of choosing N items where the first comes from the first entry in colls, the second from the second entry and so on.

NOTE: This implementation comes from Alan Malloy at this StackOverflow post. Thanks, Alan!

Accepts a sequence of collections `colls` and returns a lazy sequence of the
cartesian product of all collections.

The cartesian product of N collections is a sequences of sequences, each `N`
long, of every possible way of choosing `N` items where the first comes from
the first entry in `colls`, the second from the second entry and so on.

NOTE: This implementation comes from Alan Malloy at this [StackOverflow
post](https://stackoverflow.com/a/18248031). Thanks, Alan!
sourceraw docstring

combinationsclj/s

(combinations xs p)

Returns a lazy sequence of every possible set of p elements chosen from xs.

Returns a lazy sequence of every possible set of `p` elements chosen from
`xs`.
sourceraw docstring

factorialclj/s

(factorial n)

Returns the factorial of n, ie, the product of 1 to n (inclusive).

Returns the factorial of `n`, ie, the product of 1 to `n` (inclusive).
sourceraw docstring

list-interchangesclj/s

(list-interchanges permuted-list original-list)

Given a permuted-list and the original-list, returns the number of interchanges required to generate the permuted list from the original list.

Given a `permuted-list` and the `original-list`, returns the number of
interchanges required to generate the permuted list from the original list.
sourceraw docstring

number-of-combinationsclj/s

(number-of-combinations n k)

Returns the number of possible ways of choosing k distinct elements from a collection of n total items.

Returns the number of possible ways of choosing `k` distinct elements from a
collection of `n` total items.
sourceraw docstring

number-of-permutationsclj/s

(number-of-permutations n)

Returns the number of possible ways of permuting a collection of n distinct elements.

Returns the number of possible ways of permuting a collection of `n` distinct
elements.
sourceraw docstring

permutation-interchangesclj/s

(permutation-interchanges permuted-list)
source

permutation-parityclj/s

(permutation-parity permuted-list original-list)

Given a permuted-list and the original-list, returns the parity (1 for even, -1 for odd) of the number of the number of interchanges required to generate the permuted list from the original list.

If the two items

Given a `permuted-list` and the `original-list`, returns the parity (1 for
even, -1 for odd) of the number of the number of interchanges required to
generate the permuted list from the original list.

If the two items 
sourceraw docstring

permutation-sequenceclj/s

(permutation-sequence as)

Produces an iterable sequence developing the permutations of the input sequence of objects (which are considered distinct) in church-bell-changes order - that is, each permutation differs from the previous by a transposition of adjacent elements (Algorithm P from §7.2.1.2 of Knuth).

This is an unusual way to go about this in a functional language, but it's fun.

This approach has the side-effect of arranging for the parity of the generated permutations to alternate; the first permutation yielded is the identity permutation (which of course is even).

Inside, there is a great deal of mutable state, but this cannot be observed by the user.

Produces an iterable sequence developing the permutations of the input sequence
of objects (which are considered distinct) in church-bell-changes order - that
is, each permutation differs from the previous by a transposition of adjacent
elements (Algorithm P from §7.2.1.2 of Knuth).

This is an unusual way to go about this in a functional language, but it's
fun.

This approach has the side-effect of arranging for the parity of the generated
permutations to alternate; the first permutation yielded is the identity
permutation (which of course is even).

Inside, there is a great deal of mutable state, but this cannot be observed by
the user.
sourceraw docstring

permutationsclj/s

(permutations xs)

Returns a lazy sequence of every possible arrangement of the elements of xs.

Returns a lazy sequence of every possible arrangement of the elements of `xs`.
sourceraw docstring

permuteclj/s

(permute permutation xs)

Given a permutation (represented as a list of numbers), and a sequence xs to be permuted, construct the list so permuted.

Given a `permutation` (represented as a list of numbers), and a sequence `xs`
to be permuted, construct the list so permuted.
sourceraw docstring

sort-and-permuteclj/s

(sort-and-permute ulist <? cont)

cont = (fn [ulist slist perm iperm] ...)

Given a short list and a comparison function, to sort the list by the comparison, returning the original list, the sorted list, the permutation procedure and the inverse permutation procedure developed by the sort.

cont = (fn [ulist slist perm iperm] ...)

Given a short list and a comparison function, to sort the list by the
comparison, returning the original list, the sorted list, the permutation
procedure and the inverse permutation procedure developed by the sort.
sourceraw docstring

subpermuteclj/s

(subpermute m xs)

Given a sequence xs and a map m of replacement indices, returns a new version of xs with the element at the position marked by each key in m replaced by the element at each value in the original xs.

Given a sequence `xs` and a map `m` of replacement indices, returns a new
version of `xs` with the element at the position marked by each key in `m`
replaced by the element at each value in the original `xs`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close