I need to generate all possible combinations between {"a", "b","c"}
.
For example, an input set say like {"a", "b","c"}
, expected output is {"a", "b", "c" "ab", "ac", "bc", "abc"}
.
I need to generate all possible combinations between {"a", "b","c"}
.
For example, an input set say like {"a", "b","c"}
, expected output is {"a", "b", "c" "ab", "ac", "bc", "abc"}
.
It sounds like what you're looking for is basically a form of power set. Here's a simple implementation (taken from this site):
Note that thanks to the
<<
operator, you won't be able to use this method with lists that have more than 30 elements. I wouldn't recommend trying it with a list with close to that many elements anyway, since at 30 elements, the result set would contain 230 or 1073741824 elements.You can use this method to get the result you want like this
However, because the power set includes the null set, this will actually return the result
{"", "a", "b", "c", "ab", "ac", "bc", "abc"}
. To filter out the empty string, use this:Or more simply: