Created
October 6, 2013 18:00
-
-
Save cdfox/6857081 to your computer and use it in GitHub Desktop.
Counting the possible orderings of distinct elements [a,b,c,d,e,f] given that a < d, b < e, c < b, c < f, d
< f, d < e.
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
from itertools import permutations | |
perms = permutations(range(6)) | |
def check(p): | |
i1 = p.index(0) < p.index(3) | |
i2 = p.index(1) < p.index(4) | |
i3 = p.index(2) < p.index(1) | |
i4 = p.index(2) < p.index(5) | |
i5 = p.index(3) < p.index(4) | |
i6 = p.index(3) < p.index(5) | |
return i1 and i2 and i3 and i4 and i5 and i6 | |
print len(filter(check, perms)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment