Given a set of
n elements, the challenge is to write a function who lists all the combinations of
k elements of in this set.
Set: [1, 7, 4] Input: 2 Output: [1,7], [1,4], [7,4]
Set: ["Charlie", "Alice", "Daniel", "Bob"] Input: 2 Output ["Daniel", "Bob"], ["Charlie", "Alice"], ["Alice", "Daniel"], ["Charlie", "Daniel"], ["Alice", "Bob"], ["Charlie", "Bob"]
- The order of the output is of your choice.
- The input may be any type of data. But the output should be the same type as the input. If the input is a list of integers, the output should be a list of integers as well. If the input is a string (array of characters), the output should be a string as well.
- The code should work with any number of input variables.
- You can use any programming language.
- The answer should be able to use anything (string, int, double...) as input and output as well.
- Any built-in functions that is related to combinations and permutations are forbidden.
- Shortest code wins (in terms of bytes).
- Tiebreaker: votes.
- Duration: 1 week.
P.S. Be careful about the extreme inputs such as negative numbers, 0, etc.
combos('ab', 1) -> ['a', 'b']valid? \$\endgroup\$