Skip to content

Instantly share code, notes, and snippets.

@wrgoldstein
Last active July 9, 2023 19:33
Show Gist options
  • Save wrgoldstein/90043f61a67786a3d1847e7438a51fe2 to your computer and use it in GitHub Desktop.
Save wrgoldstein/90043f61a67786a3d1847e7438a51fe2 to your computer and use it in GitHub Desktop.
from collections import Counter
from itertools import combinations
types = [1,2,3,4]
# creatures have 2 of the 4 types
# so there are c(4,2) = 6 creatures
creatures = list(combinations(types, 2))
# there are four creatures in each ocean
sets = list(combinations(creatures, 4))
# there are three ocean levels
choices = list(combinations(sets, 3))
# we want to find the set of creatures in each ocean
# that has the same number of types in each set
def equal_subtypes(t):
(s1, s2, s3) = t
c1 = Counter([f for p in s1 for f in p])
c2 = Counter([f for p in s2 for f in p])
c3 = Counter([f for p in s3 for f in p])
return c1 == c2 and c2 == c3
solutions = filter(equal_subtypes, choices)
for l in solutions:
for c in l:
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment