diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-21 10:41:47 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-21 10:41:47 +0100 |
| commit | df7c692d3733c47b6085e660ee09334c6bc543bd (patch) | |
| tree | 5fb53112e5f627f0f486f585d5ed8e053d6a0d39 | |
| parent | bdcd78381dd5bfa4c9c3fd7194256d2030f63f5e (diff) | |
| download | aoc-df7c692d3733c47b6085e660ee09334c6bc543bd.tar.gz | |
21.1
| -rw-r--r-- | 20/py/d21.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/20/py/d21.py b/20/py/d21.py new file mode 100644 index 0000000..9f08b8c --- /dev/null +++ b/20/py/d21.py @@ -0,0 +1,36 @@ +import aoc20 +import sys +import itertools +from collections import defaultdict + + +def ingredients(line): + return line[:line.find(" (")].split(" ") + + +def allergens(line): + return line[line.find(" (contains ")+len(" (contains "):-2].split(", ") + + +def pt1(_in): + all_ingredients = [] + for line in _in: + all_ingredients.extend(ingredients(line)) + + might_be = defaultdict(lambda: set(all_ingredients)) + for line in _in: + for alg in allergens(line): + might_be[alg] &= set(ingredients(line)) + might_be = set.union(*might_be.values()) + defo_not = set(all_ingredients) - might_be + return sum(all_ingredients.count(ing) for ing in defo_not) + + +def pt2(_in): + pass + + +if __name__ == "__main__": + _in = aoc20.read_input(sys.argv[1:], 21) + print(pt1(_in)) + print(pt2(_in)) |
