The "third type of Euler Transform" takes an integer sequence that gives the number of objects of a given weight and outputs a sequences that gives the number of multisets of objects that sum to that weight.
In this code-golf challenge, you will be performing an analogous transform on lists.
Example
For example, let's say our (\$1\$-indexed) sequence is (2,1,0,0,2). We might interpret this as saying that we have
- 2 types of 1¢ coins (say copper and steel, denoted "c" and "s")
- 1 type of 2¢ coins (denoted "2")
- 0 types of 3¢ coins
- 0 types of 4¢ coins
- 2 types of 5¢ coins (say Buffalo and Jefferson, denoted "B" and "J")
Now the Euler transform tells us how many distinct ways we can make change. This (1-indexed) sequence starts
- 1¢: 2 (c/s)
- 2¢: 4 (cc/cs/ss/2)
- 3¢: 6 (ccc/ccs/css/sss/c2/s2)
- 4¢: 9 (cccc/cccs/ccss/csss/ssss/cc2/cs2/ss2/22)
- 5¢: 14 (ccccc/ccccs/cccss/ccsss/cssss/sssss/ccc2/ccs2/css2/sss2/c22/s22/B/J)
- [it continues 20, 28, 37, 48, 63, 80, 101, 124, ...]
The challenge
You will take an input which is a collection of objects and their weights in any reasonable format. For example, you might input a list of lists of strings, for example:
input = [
[], # index 0
["c", "s"], # index 1
["2"], # index 2
[], # index 3
[], # index 4
["B","J"] # index 5
]
You will then write a function which takes this collection of objects along with a positive integer n
. Your function should return all of the multisets whose weight sums to \$n\$ that are composed of the objects in the input.
For example, if you use the input
given above, and \$n=3\$, then f(input, 3)
should return something like
[
["c","c","c"],
["c","c","s"],
["c","s","s"],
["s","s","s"],
["c","2"],
["s","2"]
]
Just like the input, the output can be in any reasonable format.
This is code-golf, so shortest code wins.