From dd11e64c7a960e4ea453104d709828a4b4a92b17 Mon Sep 17 00:00:00 2001
From: a
Date: Fri, 25 Dec 2020 02:11:39 -0600
Subject: [PATCH 1/2] day 25 part 1, gotta get all 49 stars before part 2
unlocks :(
---
2020/25/25.py | 22 ++++++++++++++++++++++
2020/25/input.txt | 2 ++
2 files changed, 24 insertions(+)
create mode 100644 2020/25/25.py
create mode 100644 2020/25/input.txt
diff --git a/2020/25/25.py b/2020/25/25.py
new file mode 100644
index 0000000..5691174
--- /dev/null
+++ b/2020/25/25.py
@@ -0,0 +1,22 @@
+pubkey1 = 3418282
+pubkey2 = 8719412
+
+subject = 7
+mod = 20201227
+
+loop1 = 0
+value1 = 1
+while value1 != pubkey1:
+ value1 = (value1 * subject) % mod
+ loop1 += 1
+
+loop2 = 0
+value2 = 1
+while value2 != pubkey2:
+ value2 = (value2 * subject) % mod
+ loop2 += 1
+
+enckey1 = pow(pubkey2,loop1,mod)
+enckey2 = pow(pubkey1,loop2,mod)
+assert enckey1 == enckey2
+print(enckey1)
\ No newline at end of file
diff --git a/2020/25/input.txt b/2020/25/input.txt
new file mode 100644
index 0000000..48809f6
--- /dev/null
+++ b/2020/25/input.txt
@@ -0,0 +1,2 @@
+3418282
+8719412
\ No newline at end of file
From 531b842dfc18b8a126a417262b4e33607e40fc73 Mon Sep 17 00:00:00 2001
From: a
Date: Fri, 25 Dec 2020 02:46:36 -0600
Subject: [PATCH 2/2] i still don't really understand this
---
2020/21/21.py | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/2020/21/21.py b/2020/21/21.py
index 2bb3fc6..c08e4bf 100644
--- a/2020/21/21.py
+++ b/2020/21/21.py
@@ -1,16 +1,58 @@
def main():
- with open("input_sample.txt") as f:
+ with open("input.txt") as f:
lines = f.read().split('\n')
+ foods = [s[:-1].split(' (contains ') for s in lines]
+ # map allergens to possible ingredients
+ possible = [
+ (allergen, set(food[0].split(' ')))
+ for food in foods
+ for allergen in food[1].split(', ')
+ ]
+ # get sets of all allergens and all ingredients
+ allergens = {p[0] for p in possible}
+ ingredients = set.union(*[p[1] for p in possible])
+ # find which ingredients are always listed for a given allergen
+ possible = {
+ a:set.intersection(*[
+ s[1]
+ for s in possible
+ if s[0] == a]
+ ) for a in allergens
+ }
+ # reduce
+ while any({i for i in possible if len(possible[i]) > 1}):
+ for b in {j for j in possible if len(possible[j]) > 1}:
+ for a in {i for i in possible if len(possible[i]) == 1}:
+ possible[b] -= possible[a]
+ # find sets of allergenic and non-allergenic
+ unsafe = set.union(*list(possible.values()))
+ safe = ingredients - unsafe
+ #
+ print('|non-allergen occurrences| =', sum(
+ food[0].split().count(s)
+ for food in foods
+ for s in safe)
+ )
+ print('allergens:', ','.join(
+ [
+ list(possible[a])[0]
+ for a in sorted(list(possible))
+ ])
+ )
+
+ """
all_ingredients = set()
all_allergens = set()
may_contain = {}
unsafe_ingredients = {}
+ foods = []
for line in lines:
ingredients, contains = line.split(' (contains ')
ingredients = ingredients.split(' ')
contains = contains[:-1].split(', ') # remove trailing ")" then split
all_ingredients = all_ingredients | set(ingredients)
all_allergens = all_allergens | set(contains)
+ """
if __name__ == "__main__":
main()
\ No newline at end of file