summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-02 06:27:10 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-02 06:27:10 +0100
commitb4cefdca7c5269b49ece02fb023bd451ae0f906d (patch)
tree40a88f65b399561e0793735529873939f734b651 /20
parentad2b66d6540be74194ead0eb67d060312178052d (diff)
downloadaoc-b4cefdca7c5269b49ece02fb023bd451ae0f906d.tar.gz
day 02
Diffstat (limited to '20')
-rw-r--r--20/py/d02.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/20/py/d02.py b/20/py/d02.py
new file mode 100644
index 0000000..572404e
--- /dev/null
+++ b/20/py/d02.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+def pt1(_in):
+ valid = 0
+ for passwd in _in:
+ want, have = passwd.split(":")
+ want_num, want_char = want.split()
+ want_min, want_max = [int(s) for s in want_num.split("-")]
+ if want_min <= have.count(want_char) <= want_max:
+ valid += 1
+ return valid
+
+
+def pt2(_in):
+ valid = 0
+ for passwd in _in:
+ want, have = passwd.split(":")
+ want_num, want_char = want.split()
+ want_first, want_second = [int(s) for s in want_num.split("-")]
+ matches = 0
+ if have[want_first] == want_char:
+ matches += 1
+ if have[want_second] == want_char:
+ matches += 1
+ if matches == 1:
+ valid += 1
+ return valid
+
+
+if __name__ == "__main__":
+ input = open("../input/02", "r").readlines()
+ print(pt1(input))
+ print(pt2(input))