Skip to content

Instantly share code, notes, and snippets.

@cdfox
Created October 6, 2013 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdfox/6857081 to your computer and use it in GitHub Desktop.
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.
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