summary refs log tree commit diff stats
path: root/day16.py
diff options
context:
space:
mode:
Diffstat (limited to 'day16.py')
-rw-r--r--day16.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/day16.py b/day16.py
new file mode 100644
index 0000000..45cc6d3
--- /dev/null
+++ b/day16.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+from collections import defaultdict
+import re
+
+target = {
+    'children': 3,
+    'cats': 7,
+    'samoyeds': 2,
+    'pomeranians': 3,
+    'akitas': 0,
+    'vizslas': 0,
+    'goldfish': 5,
+    'trees': 3,
+    'cars': 2,
+    'perfumes': 1
+}
+
+info_re = re.compile(r'(\w+): (\d)')
+
+# part 1
+with open('day16.txt') as data:
+    for num, line in enumerate(data):
+        current = dict(map(lambda x: (x[0], int(x[1])), info_re.findall(line)))
+        if all(target[key] == current[key] for key in current):
+            print(num+1)
+            break
+
+# part 2
+def valid(curr):
+    for key in curr:
+        if key == 'cats' or key == 'trees':
+            yield curr[key] > target[key]
+        elif key == 'pomeranians' or key == 'goldfish':
+            yield curr[key] < target[key]
+        else:
+            yield curr[key] == target[key]
+
+with open('day16.txt') as data:
+    for num, line in enumerate(data):
+        current = dict(map(lambda x: (x[0], int(x[1])), info_re.findall(line)))
+        if all(valid(current)):
+            print(num+1)
+            break