]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blobdiff - day02/get_valid_count.py
Move to have day be 2 digit always
[advent-of-code-2020.git] / day02 / get_valid_count.py
diff --git a/day02/get_valid_count.py b/day02/get_valid_count.py
new file mode 100644 (file)
index 0000000..0b65b82
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+import regex
+
+total_lines=0
+valid_lines=0
+for line in open("input.txt", "r"):
+    total_lines += 1
+    (min_count, max_count, letter, password) = regex.match('([0-9]+)-([0-9]+) ([a-z]): ([a-z]*)', line).group(1,2,3,4)
+    min_count=int(min_count)
+    max_count=int(max_count)
+    count = 0
+    for x in password:
+        if x == letter:
+            count += 1
+    if count >= min_count and count <= max_count:
+        valid_lines += 1
+
+print(valid_lines, "valid lines of", total_lines)