-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.py
37 lines (26 loc) · 847 Bytes
/
2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import re
def parse_line(l):
pos, target, passwd = re.match(r"(\d+-\d+) (.): (.*)", l).groups()
positions = [int(x) for x in pos.split("-")]
return positions, target, passwd
def count_falls_in_range(string, char, count_range):
return string.count(char) in count_range
def one_index_has_char(string, char, indices):
return (string[indices[0] - 1] == char) != (string[indices[1] - 1] == char)
def main():
parsed_lines = [parse_line(l) for l in sys.stdin]
ans1 = sum(
[
count_falls_in_range(password, target, range(ns[0], ns[1] + 1))
for ns, target, password in parsed_lines
]
)
ans2 = sum(
[
one_index_has_char(password, target, ns)
for ns, target, password in parsed_lines
]
)
print(ans1, ans2)
main()