From 34f71edd66e22b7d1e1b262d92d80e1bf335aa57 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Mon, 25 Jan 2021 12:34:50 -0700 Subject: Initial commit --- day2/day2.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 day2/day2.py (limited to 'day2/day2.py') 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) -- cgit v1.2.3