Print all the ways to aquire specific number using only specific numbers
Jelly, 10 bytes
ŒṗfƑƇL=¥Ƈ⁵
Try it online!
A full program that takes the total, token values and number of arguments as its arguments. Returns a list of lists of token values.
Explanation
Œṗ | Integer partition (of first argument)
Ƈ | Keep only those which:
Ƒ | - are invariant when:
f | - filtered to only include the (implicit) second argument.
¥Ƈ | Keep only those for which:
L | - the length
= ⁵ | - is equal to the third argument
J, 35 32 bytes
~.@((=1&#.)#])2+#&4/:~@#:[:i.4^]
Try it online!
- Count in base 4 from 0 up to
4 ^ num_tokens
to generate all the raw possibilities:#&4/:~@#:[:i.4^]
- Add 2 to all numbers so the tokens will have 2 3 4 5 labels instead of 0 1 2 3 labels:
2+
- Sort each possibility in preparation for removing dups:
/:~@
- Filter the raw possibilities to include only those with the correct sum:
((=1&#.)#])
- Take the uniqs:
~.@
Perl 6, 64 bytes
{grep(*.sum==$_,|($/=2..5),|(+<<[\X] $/xx$_)[*;*])>>.Bag.unique}
Try it online!
Fails for inputs above 7 due to Too many arguments in flattening array.
This is because we are generating a list of every possible combination with repetition of numbers up to length n (where n is the same as the input), and not just that, but every possible ordering as well. Ah well, the price of being golfy...
This takes a number and returns a Bag, which is an unordered list of numbers and the amount in the bag.