SHARE
TWEET

Untitled

a guest Jul 17th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. test = "input001.txt"
  2.  
  3. i = -1
  4. sets = []
  5. items = set()
  6. # for line in open(argv[1], 'r').readlines():
  7. for line in open(test, 'r').readlines():
  8.     if i == -1:
  9.         n = int(line.strip())
  10.     elif i < n:
  11.         tokens = line.strip().split(",")
  12.         set = []
  13.         for x in tokens:
  14.             item = x.strip()
  15.             set.append(item)
  16.             items.add(item)
  17.         sets.append(set)
  18.     i=i+1
  19.  
  20. def power_set(items, baskets):
  21.     for currSub in self.get_powerset(items):
  22.         combo = set(currSub)
  23.         curr_count = 0
  24.         for sub in baskets:
  25.             if combo.issubset(sub) and len(combo) > 0:
  26.                 curr_count += 1
  27.         if curr_count != 0:
  28.             print(str(curr_count) + " => " + str(currSub).replace("(", "[").replace(")", "]").replace("'", ""))
  29.  
  30. def get_powerset(self, seq):
  31.     if len(seq) <= 1:
  32.         yield seq
  33.         yield []
  34.     else:
  35.         for item in self.powerset(seq[1:]):
  36.             yield [seq[0]] + item
  37.             yield item
  38.  
  39. print("Items: " + str(items).replace("{", "[").replace("}", "]").replace("'", "").replace("set(", "").replace(")", ""))
  40. print("Number of baskets: " + str(n))
  41. power_set(items, sets)
RAW Paste Data
Top