2020 - Day 2
This commit is contained in:
parent
35dfc4deaa
commit
6e70bcbf72
|
@ -0,0 +1,16 @@
|
|||
input = []
|
||||
with open('day2_input.txt', 'r') as f:
|
||||
for line in f.readlines():
|
||||
line = line.split(' ');
|
||||
a,b = line[0].split('-');
|
||||
input.append(((int(a),int(b)), line[1][0], line[2].strip()))
|
||||
|
||||
def check_pwd(p):
|
||||
rule, char, pwd = p[0], p[1], p[2]
|
||||
cnt = pwd.count(char)
|
||||
if cnt >= rule[0] and cnt <= rule[1]:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
print(sum(map(check_pwd, input)))
|
|
@ -0,0 +1,15 @@
|
|||
input = []
|
||||
with open('day2_input.txt', 'r') as f:
|
||||
for line in f.readlines():
|
||||
line = line.split(' ');
|
||||
a,b = line[0].split('-');
|
||||
input.append(((int(a),int(b)), line[1][0], line[2].strip()))
|
||||
|
||||
def check_pwd(p):
|
||||
rule, char, pwd = p[0], p[1], p[2]
|
||||
if (pwd[rule[0]-1] == char or pwd[rule[1]-1] == char) and (pwd[rule[0]-1] != pwd[rule[1]-1]):
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
print(sum(map(check_pwd, input)))
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue