For a while now, the permutations function in the combinatorics library has
had special handling for lists with duplicate items.

Example: (permutations [1 2 3]) -> ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2)
(3 2 1))
Example: (permutations [1 1 2]) -> ((1 1 2) (1 2 1) (2 1 1))

The new release, version 0.1.0 extends this intelligent handling of
duplicate items to combinations and subsets.

There are straightforward computations for counting permutations,
combinations, and subsets of n distinct items -- so straightforward it
never seemed worth adding to the library.  However, now with the special
handling of duplicates, it seems very natural to want to know things like:

(count-permutations [1 1 1 2 2 2]) -> 20  ;not 6!

So I've added count-permutations, count-combinations, and count-subsets
which do the obvious things for lists with no duplicates, but for lists
with duplicates, computes the count taking into account the special
handling of lists with duplicates.  It computes these counts directly, not
by iterating through the actual stream of permutations/combinations/subsets.

Similarly, there is now a way to compute the nth
permutation/combination/subset without iterating through the result stream.

I've also added two new permutation-related functions:
drop-permutations lets you efficiently skip over some number of
permutations before starting the stream of results.

permutation-index is like nth-permutation in reverse - from a scrambled
sortable collection, it will tell you how far into the lexicographic stream
of permutations it is located (computed directly without iterating through
the stream).

So now you can easily find out in the blink of an eye, for example, that
"clojurecombinatoricsrocks" is the 169001484919860315564th permutation
(0-based) of "abcccceiijklmnoooorrrsstu"

Didn't your life feel empty before learning that important fact?

Enjoy the new functionality!

https://github.com/clojure/math.combinatorics

--Mark Engelberg

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to