summaryrefslogtreecommitdiff
path: root/day2/day2.py
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-01-25 12:34:50 -0700
committerCody Hiar <cody@hiar.ca>2021-01-25 12:34:50 -0700
commit34f71edd66e22b7d1e1b262d92d80e1bf335aa57 (patch)
treeab37eb9345f859b1de50aba7869ea39e35b700a1 /day2/day2.py
Initial commit
Diffstat (limited to 'day2/day2.py')
-rw-r--r--day2/day2.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/day2/day2.py b/day2/day2.py
new file mode 100644
index 0000000..4c68e63
--- /dev/null
+++ b/day2/day2.py
@@ -0,0 +1,25 @@
+import re
+from IPython import embed
+
+data = [str.strip(x) for x in open("input")]
+
+pattern = r"(\d+)-(\d+) ([a-z]): ([a-z]+)"
+prog = re.compile(pattern)
+
+# Part 1
+
+valid_count = 0
+for x in data:
+ low, high, char, password = prog.match(x).groups()
+ if int(low) <= password.count(char) <= int(high):
+ valid_count += 1
+print(valid_count)
+
+# Part 2
+
+valid_count = 0
+for x in data:
+ low, high, char, password = prog.match(x).groups()
+ if [password[int(low) - 1], password[int(high) - 1]].count(char) == 1:
+ valid_count += 1
+print(valid_count)