]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day02/get_valid_count.py
Looks like I forget to commit Day 10!
[advent-of-code-2020.git] / day02 / get_valid_count.py
1 #!/usr/bin/python3
2
3 import regex
4
5 total_lines=0
6 valid_lines=0
7 for line in open("input.txt", "r"):
8     total_lines += 1
9     (min_count, max_count, letter, password) = regex.match('([0-9]+)-([0-9]+) ([a-z]): ([a-z]*)', line).group(1,2,3,4)
10     min_count=int(min_count)
11     max_count=int(max_count)
12     count = 0
13     for x in password:
14         if x == letter:
15             count += 1
16     if count >= min_count and count <= max_count:
17         valid_lines += 1
18
19 print(valid_lines, "valid lines of", total_lines)