-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.py
47 lines (33 loc) · 987 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
39
40
41
42
43
44
45
46
47
path = "./Inputs/day2.txt"
#path = "./Inputs/day2Test.txt"
def part1():
file = open(path, "r")
lines = file.readlines()
count = 0
for line in lines:
parts = line.split(" ")
min, max = map(int, parts[0].split("-"))
letter = parts[1].replace(':', '')
password = parts[2]
occurences = password.count(letter)
if(occurences >= min and occurences <= max):
count += 1
print("Part 1:")
print(count)
file.close()
def part2():
file = open(path, "r")
lines = file.readlines()
count = 0
for line in lines:
parts = line.split(" ")
char1, char2 = map(int, parts[0].split("-"))
letter = parts[1].replace(':', '')
password = parts[2]
if(password[char1-1] == letter) is not (password[char2-1] == letter):
count += 1
print("Part 2:")
print(count)
file.close()
part1()
part2()