-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02.py
More file actions
54 lines (40 loc) · 1.06 KB
/
02.py
File metadata and controls
54 lines (40 loc) · 1.06 KB
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
"""Wed, 2 Dec"""
from puzzles import get_puzzle
puzzle = get_puzzle(2)
def test():
example = [
"1-3 a: abcde",
"1-3 b: cdefg",
"2-9 c: ccccccccc",
]
assert one(example) == 2
assert two(example) == 1
def one(puzzle: list):
valid = 0
for line in puzzle:
limits, pattern, password = line.split()
char = pattern[0]
lower, upper = map(int, limits.split("-"))
num = 0
for c in password:
if c == char:
num += 1
if lower <= num and num <= upper:
valid += 1
return valid
def two(puzzle: list):
valid = 0
for line in puzzle:
limits, pattern, password = line.split()
char = pattern[0]
lower, upper = map(int, limits.split("-"))
# zero-index
lc = password[lower - 1]
uc = password[upper - 1]
if (lc == char and uc != char) or (lc != char and uc == char):
valid += 1
return valid
if __name__ == "__main__":
test()
print(one(puzzle))
print(two(puzzle))