Created
May 17, 2020 16:01
-
-
Save tlylt/4338750037c08e33a1ecbf1c48174b35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number of Combinations = 2**(length of input set) | |
# Makes use of binary | |
def PowerSet(input): | |
ans = [] | |
numOfComb = 2 ** len(input) | |
for combidx in range(numOfComb): # 0 -> numOfComb | |
temp = [] | |
for setidx in range(len(input)): # 0 -> len(input) | |
if combidx & 1 << setidx: # bitwise operation e.g. 0 & 1 << 0 =>0 | |
temp.append(input[setidx]) | |
ans.append(temp) | |
return ans | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment