], [1, 3], [0, 2, 4]]
[[5], [1, 4], [0, 2, 3]]
[[5], [2, 3], [0, 1, 4]]
[[5], [2, 4], [0, 1, 3]]
[[5], [3, 4], [0, 1, 2]]
]

[1, 1, 4] -> [
[[0], [1], [2, 3, 4, 5]]
[[0], [2], [1, 3, 4, 5]]
[[0], [3], [1, 2, 4, 5]]
[[0], [4], [1, 2, 3, 5]]
[[0], [5], [1, 2, 3, 4]]
[[1], [2], [0, 3, 4, 5]]
[[1], [3], [0, 2, 4, 5]]
[[1], [4], [0, 2, 3, 5]]
[[1], [5], [0, 2, 3, 4]]
[[2], [3], [0, 1, 4, 5]]
[[2], [4], [0, 1, 3, 5]]
[[2], [5], [0, 1, 3, 4]]
[[3], [4], [0, 1, 2, 5]]
[[3], [5], [0, 1, 2, 4]]
[[4], [5], [0, 1, 2, 3]]
]


This is the fifth and final challenge of the RGS Golfing Showdown. If you want to participate in the competition, you have 96 hours to submit your eligible answers. Remember there is still 300 reputation in prizes! (See 6 of the rules)

Also, as per section 4 of the rules in the linked meta post, the "restricted languages" for this third challenge are only Sledgehammer, J and Mathematica so submissions in these languages are not eligible for the final prize. But they can still be posted!!

## Final prize

If you want to be considered for the final prize, at the end of your answer to this challenge please add a link to the eligible submissions you want to be considered for your final score, as well as the scores those answers got! This way it will be slightly easier for me to keep track of everything. Thanks!

This is still a regular challenge, so enjoy!

• For the first test case why isn't [[0],[1],[2],[3],[4],[5],[7],[6]] valid? Mar 11 '20 at 11:28
• @ExpiredData My understanding is that the output is a multiset as well, so this would just be a different representation of the same output -- and that would be valid as long as you return only one of them. Mar 11 '20 at 11:36
• @Arnauld thanks for your feedback. Tbh ordering the representation of l isn't of interest. I say we can assume the representation of l is ordered.
– RGS
Mar 11 '20 at 13:25

# 05AB1E, 9 bytes

œεI£€{{}ê


Try it online!

œ           # permutations of the [0,..., n-1] input
ε     }    # for each permutation:
I£        #  cut it in parts of lengths given by the second input
€{      #  sort each part
{     #  sort the list of parts
ê   # sort and uniquify the list of lists of parts

• Dang, you make it look so simple!.. :D Mar 11 '20 at 13:59
• Hey there, are you competing for the final prize of the RGS Golfing Showdown? If so, please include links to the answers of the previous challenges you want to submit! Thanks :)
– RGS
Mar 14 '20 at 22:58
• @RGS no, i'm not. Mar 15 '20 at 3:07

# Python 3, 123118114 112 bytes

Input: set s representing a list of n unique elements, and an iterable l representing the multiset.

Output: a set of all partitions, where each partition is a tuple of tuples of elements (aka output is a set of tuples of tuples).

lambda s,l:{(*sorted(p),)for p in product(*(combinations(s,i)for i in l))if{*sum(p,p)}>s}
from itertools import*


Try it online!

## Approach

Step 1: For each element i of the multiset l, we find all combinations of i elements of s. We then find the Cartesian products of them. This is the list of candidate partitions.
For example: for l = [1,2], s = ABC, we first find all combinations

• of 1 element: A, B, C
• of 2 elements: AB, AC, BC

The candidate partitions are the Cartesian product of the above list of combinations:

[A,AB]
[A,AC]
[A,BC]
[B,AB]
[B,AC]
[B,BC]
[C,AB]
[C,AC]
[C,BC]


Step 2: Filter out the invalid partitions (partitions that do not add up to s).
For the above example, only the following partitions are kept:

[A,BC]
[B,AC]
[C,AB]


## Code breakdown

lambda s,l:
{
(*sorted(p),)                     # convert partition to a sorted tuple (of tuples)
for p in product(                 # for each candidate partition
*(combinations(s,i)for i in l)
)
if{*sum(p,p)}>s                   # keep only if partition add up to s
}                              # put everything in a set to filter out duplicates


Each partition is stored as a sorted tuple of sorted tuple. This ensure no duplicate in the final result.

{*sum(p,p)}>s checks if a candidate partition is valid (aka contains all element in s). This work by putting all elements in the partition and some extra elements into a set, then check if the set is a superset of s.

For example: for s={0,1,2,3} and valid partition p=((0,1),(2,3)):
sum(p,p) evaluates to ((0,1),(2,3),0,1,2,3), which when converted into set is a superset of s.

For s={0,1,2,3} and invalid partition p=((0,1),(1,2)):
sum(p,p) evaluates to ((0,1),(1,2),0,1,2), which when converted into set becomes {0,1,2,(0,1),(1,2)}, not a superset of s.

# JavaScript (ES6),  158 156  141 bytes

Takes input as (a)(r), where $$\a\$$ is the representation of the input set $$\l\$$ as an ordered array, and $$\r\$$ is the range $$\[1,2,...,n]\$$.

Prints the results.

a=>r=>(F=(k,m,o=[],p,s=[],n=a[k])=>n?s[n-1]?F(++k,m,[...o,s],a[k]-n?0:s[0]):r.map(i=>i<p|m>>i&1||F(k,m|1<<i,o,i,[...s,i])):console.log(o))(0)


Try it online!

### Commented

a =>                      // a[] = ordered representation of the input set
r => (                    // r[] = range [1, 2,..., n]
F = (                   // F is a recursive function taking:
k,                    //   k = index of the current entry in a[]
m,                    //   m = bitmask of values already assigned in the output
o = [],               //   o[] = output
p,                    //   p = either 0 or a previous value (as a lower bound)
s = [],               //   s[] = array representing the current set
n = a[k]              //   n = k-th entry in a[]
) =>                    //
n?                   // if n is defined:
s[n - 1]?          //   if the current set is not full:
F(                //     do a recursive call:
++k,            //       increment k
m,              //       pass m unchanged
[...o, s],      //       append s[] to o[]
a[k] - n? 0    //       set p to 0 if the next set has a different size
: s[0] //       or to s[0] if it has the same size
)                 //     end of recursive call
:                   //   else:
r.map(i =>        //     for each value i in the range r[]:
i < p |         //       abort if i is less than p
m >> i &