-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathday2.py
31 lines (25 loc) · 767 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
def part1(lines):
count = 0
for line in lines:
limits, letter, password = line.split(' ')
min_limit, max_limit = map(int, limits.split('-'))
letter = letter[0]
if max_limit >= password.count(letter) >= min_limit:
count += 1
return count
def part2(lines):
count = 0
for line in lines:
index, letter, password = line.split(' ')
index1, index2 = map(int, index.split('-'))
letter = letter[0]
if bool(password[index1-1] == letter) != bool(password[index2-1] == letter):
count += 1
return count
with open('day2-data.txt') as f:
inputs = [
line
for line in f.read().splitlines()
]
print(part1(inputs))
print(part2(inputs))