daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 204 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. 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.
  3. """
  4.  
  5. from itertools import combinations
  6. from random import shuffle
  7. from pprint import pprint
  8.  
  9. n_animals = 31
  10. n_animals_per_card = 6
  11.  
  12. print(
  13.     "number of possible combinations:",
  14.     len(list(combinations(range(n_animals), n_animals_per_card))),
  15. )
  16.  
  17. decks = []
  18. cards = []
  19. while len(cards) < 30:
  20.  
  21.     combs = list(combinations(range(n_animals), n_animals_per_card))
  22.     shuffle(combs)
  23.  
  24.     cards = [set(combs[0])]
  25.  
  26.     for combination in combs:
  27.         valid_comb = True
  28.         combination_set = set(combination)
  29.         for card in cards:
  30.             if not len(card.intersection(combination_set)) == 1:
  31.                 valid_comb = False
  32.                 break
  33.         if valid_comb:
  34.             cards.append(combination_set)
  35.  
  36.     cards = [list(card) for card in cards]
  37.     print("size of current carddeck:", len(cards))
  38.  
  39.     decks.append(cards)
  40. pprint(decks[-1])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top