mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-13 22:33:34 +02:00
2020 - Day 2
This commit is contained in:
16
2020/day2_1.py
Normal file
16
2020/day2_1.py
Normal 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
15
2020/day2_2.py
Normal 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
1000
2020/day2_input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user