Created
November 18, 2015 21:47
-
-
Save benjaminaaron/c375b8a751f88bc77889 to your computer and use it in GitHub Desktop.
subgroups and permutations in python
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
Set = ['A', 'B', 'C', 'D'] | |
Subsets = [] | |
n = len(Set) | |
for i in xrange(pow(2, n)): | |
binaryDigits = (bin(i)[2:]).zfill(n) | |
subset = '' | |
j = 0 | |
for digit in binaryDigits: | |
if(digit == '1'): | |
subset += Set[j] | |
j += 1 | |
Subsets.append(subset) | |
print 'distinct subgroups in set', Set, ':' | |
print Subsets | |
# - - - - - - - - - - - - - - - - - | |
import itertools | |
print 'permutations of set', Set, ':' | |
print list(itertools.permutations(Set)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment