-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
38 lines (33 loc) · 967 Bytes
/
day2.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
38
with open('day2_in.txt', 'r') as f:
numRight = 0
lines = f.read().split("\n")
for line in lines:
if line == "":
continue
line = line.split()
interval = line[0].split("-")
letter = line[1]
letter = letter[:-1]
password = line[2]
occurence = 0
for c in password:
if c == letter:
occurence += 1
if occurence >= int(interval[0]) and occurence <= int(interval[1]):
numRight += 1
print(numRight)
numRight = 0
for line in lines:
if line == "":
continue
line = line.split()
interval = line[0].split("-")
letter = line[1]
letter = letter[:-1]
password = line[2]
occurence = 0
c1 = password[int(interval[0]) - 1] == letter
c2 = password[int(interval[1]) - 1] == letter
if c1 is not c2:
numRight += 1
print(numRight)