2020 - Day 2

This commit is contained in:
Jonas Neugebauer 2020-12-09 15:37:29 +01:00
parent 35dfc4deaa
commit 6e70bcbf72
3 changed files with 1031 additions and 0 deletions

16
2020/day2_1.py Normal file
View File

@ -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)))

15
2020/day2_2.py Normal file
View File

@ -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)))

1000
2020/day2_input.txt Normal file

File diff suppressed because it is too large Load Diff