Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- There are 31 different animals and we want to have a deck of cards such that on each card there are 6 animals and every card has exactly one animal in common with every other card. Our card deck should have at least 30 cards.
- """
- from itertools import combinations
- from random import shuffle
- from pprint import pprint
- n_animals = 31
- n_animals_per_card = 6
- print(
- "number of possible combinations:",
- len(list(combinations(range(n_animals), n_animals_per_card))),
- )
- decks = []
- cards = []
- while len(cards) < 30:
- combs = list(combinations(range(n_animals), n_animals_per_card))
- shuffle(combs)
- cards = [set(combs[0])]
- for combination in combs:
- valid_comb = True
- combination_set = set(combination)
- for card in cards:
- if not len(card.intersection(combination_set)) == 1:
- valid_comb = False
- break
- if valid_comb:
- cards.append(combination_set)
- cards = [list(card) for card in cards]
- print("size of current carddeck:", len(cards))
- decks.append(cards)
- pprint(decks[-1])
Add Comment
Please, Sign In to add comment