Re: Combinatorics partitions that preserves adjacency?

2017-03-17 Thread Steve Miner
For what it’s worth, I gave your problem a try and come up with the following implementation based on Mark Engelberg’s suggestion. It should do less generating work up front so you don’t have to filter unwanted results. This code depends on `combinations` preserving the order of the items.

Re: Combinatorics partitions that preserves adjacency?

2017-03-16 Thread Paul Gowder
For sake of completeness/if this is useful for anyone else, a full implementation of the number-the-possible-split-locations method, including the original API with :min and :max options. Could probably be tidied up with transducers and such for all those filters but does the job. (require

Re: Combinatorics partitions that preserves adjacency?

2017-03-16 Thread Paul Gowder
Ooh, thank you---those are both lovely solutions! -- 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.

Re: Combinatorics partitions that preserves adjacency?

2017-03-15 Thread Mark Engelberg
Think in terms of numbering the possible split locations: a b c 1 2 So the possible partitions are represented by [1], [2], [1 2], i.e., all the non-empty subsets of [1 2]. So write a function that goes from this numbering scheme to partitions (e.g., using subvec) and use combinatorics'

Re: Combinatorics partitions that preserves adjacency?

2017-03-15 Thread Mikera
Filtering and sorting each partition is going to be pretty expensive! If the list is long you will be discarding most of the results anyway. I found a recursive way to do this that is fairly efficient, by observing that you either want to join two adjacent elements together in a partition or

Combinatorics partitions that preserves adjacency?

2017-03-15 Thread Paul Gowder
Hi everyone, Does anyone know of a straightforward way to get something like clojure.math/combinatorics/partitions that works more like partition in the core library, that is, that only selects partitions with adjacent elements? In other words, right now this is the problem: (require