]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day2/get_valid_count_2.py
471e389b887d3dda458c95a793fcebbc510d7158
[advent-of-code-2020.git] / day2 / get_valid_count_2.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     (pos1, pos2, letter, password) = regex.match('([0-9]+)-([0-9]+) ([a-z]): ([a-z]*)', line).group(1,2,3,4)
10     pos1 = int(pos1)
11     pos2 = int(pos2)
12     if (password[pos1-1] == letter or password[pos2-1] == letter) and password[pos1-1] != password[pos2-1]:
13         valid_lines += 1
14
15 print(valid_lines, "valid lines of", total_lines)