clojure - Partition specific sets -
I want to use Closer to split a specific set:
For example: a Vector is [1 2 3 4 5]
. Apart from this, there is also a map, such as {2 1, 3 1}
, which means that 1 set generates 2 elements, and 1 set that contains 3 elements.
(some_function {2 1, 3 1} [1 2 3 4 5]) ;; I only want this: (([1 2 3] [4 5]) ([1 2 4] [3 5]) ([1 2 5] [3 4]) ([1 2] [3 4 5] ) ([1 3 4] [2 5]) ([1 3 5] [2 4]) ([1 3] [2 4 5]) ([1 4 5] [2 3]) ([1 4] [2 3 5]) ([1 5] [2 3 4]))
Earlier, I thought that all the cases should be used to generate, and then the basis of the situation Filter on, but it is very disabled when you have a big vector like [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17]
and such as { 5 1, 6 2} (Generate 1 set containing 5 elements, and 2 sets containing 6 elements)
. I just want to generate for the first time, how can I do this work?
In these specific examples you give, there are 5717,712 divisions that meet those constraints , And there are not enough chances with any obstacles. So it is not enough that the composer is disabled; I think that you just see how many possibilities are minimized.
Combination work is a great tool for getting more straightforward combinations looking for you.
In your example, / P>
(def special-partition ([initial listing [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17]] ( [C1 (Initial-list of combinations 5): [Balance 1 (Remove (set C1) initial-list) C2 (combination remaining 1 6): Two [remaining 2 (remove C2) balance 1)] ] [C 1C 2 remaining 2])) =) () special-segmentation) ([(1 2 3 4 5) (6 7 8 9 10 11) (12 13 14 15 16 17)] [(1 2 3 4 5) (6 7 8 9 10 12) (11 13 14 15 16 17)] [(1 2 3 4 5) (6 7 8 9 10 13) (11 12 14 15 16 17)] [(1 2 3 4 5) (6 7 8 9 10 14) (11 12 13 15 16 17)] [(1 2 3 4 5) (6 7 8 9 10 15) (11 12 13 14 16 17)] [(1 2 3 4 5) (6 7 8 9 10 16) (11 12 13 14 15 17)] [(1 2 3 4 5) (6 7 8 9 10 17) (11 12 13 14 15 16)] [(1 2 3 4 5) (6 7 8 9 11 12) (10 13 14 15 16 17)] [(1 2 3 4 5) (6 7 8 9 11 13) (10 12 14 15 16 17)] [(1 2 3 4 5) (6 7 8 9 11 14) (10 12 13 15 16) 17)]
It is still a large number of divisions, but at least now you are generating them directly.
By this example, you get this technique a function that takes an arbitrary map describing the partition structure, as you described in your question.
Your initial set contains duplicate elements that will need to be removed slightly separately.
Comments
Post a Comment