Skip to content

Instantly share code, notes, and snippets.

@milleniumbug
Created July 31, 2015 22: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 milleniumbug/cad223811cc682452b71 to your computer and use it in GitHub Desktop.
Save milleniumbug/cad223811cc682452b71 to your computer and use it in GitHub Desktop.
import collections, csv, itertools
recipes = collections.defaultdict(set)
tolerance = 0
with open('rec.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
recipes[row[0]].add(row[1])
def get_text(base_factory_item_name, related_factory_item_name, needed_items_list):
default_text = "Factory of {} can also produce {}, just add {}"
noadd_text = "Factory of {} can also produce {}"
if needed_items_list:
return default_text.format(base_factory_item_name,
related_factory_item_name,
",".join(needed_items_list))
else:
return noadd_text.format(base_factory_item_name, related_factory_item_name)
for left, right in itertools.product(recipes, repeat=2):
if left != right and recipes[right].issuperset(recipes[left]):
needed_items_list = recipes[right] - recipes[left]
if len(needed_items_list) <= tolerance:
print(get_text(left, right, needed_items_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment