-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayTwo.py
62 lines (47 loc) · 1.31 KB
/
dayTwo.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# q1
values = []
with open("dayTwo.txt") as file:
for line in file:
line = line.rstrip()
line = line.replace(":", "")
line = line.replace("-", " ")
values.append(line)
def isValid(password, low, high, specified_letter):
count = 0
for i in range(len(password)):
if password[i] == specified_letter:
count += 1
if count > high:
return False
if count < low:
return False
return True
count = 0
for val in values:
val = val.split()
# print(val)
low = int(val[0])
high = int(val[1])
specified_letter = val[2]
password = val[3]
if isValid(password, low, high, specified_letter):
count += 1
print(count)
# q2
def isValidModified(password, low, high, specified_letter):
if password[low - 1] == specified_letter and password[high-1] == specified_letter:
return False
elif password[low - 1] == specified_letter or password[high-1] == specified_letter:
return True
return False
counter = 0
for val in values:
val = val.split()
# print(val)
low = int(val[0])
high = int(val[1])
specified_letter = val[2]
password = val[3]
if isValidModified(password, low, high, specified_letter):
counter += 1
print(counter)