This question already has an answer here:
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 of input. If the input is a list of integers, the output should be a list of inputs as well. If the input is a string (array of characters), the output should be a string as well.
- The code should work in any number of input variables.
- Shortest code wins (in terms of bytes).
- 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.
- Tiebreaker: votes.
- Duration: 1 week.
P.S. Be careful about the extreme inputs such as negative numbers, 0, etc.