Init (tm day3)

This commit is contained in:
2020-12-06 15:47:12 +01:00
commit 4d05cc0bb9
7 changed files with 1405 additions and 0 deletions

45
day2/day2.py Normal file
View File

@@ -0,0 +1,45 @@
import os
import re
def validate_password(line):
parts = re.split('([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', line)
lower = int(parts[1])
upper = int(parts[2])
char = parts[3]
password = parts[4]
password = re.sub('[^%s]'% char, '', parts[4])
length = len(password)
if(length >= lower and length <= upper):
return True
def validate_password_2(line):
parts = re.split('([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', line)
lower = int(parts[1]) - 1
upper = int(parts[2]) - 1
char = parts[3]
password = parts[4]
if((password[lower] is char) is not (password[upper] is char)):
return True
def part1():
count = 0
with open("day2/input.txt") as input:
for line in input:
if validate_password(line) == True:
count += 1
print("Day 1: %d"% count)
def part2():
count = 0
with open("day2/input.txt") as input:
for line in input:
if validate_password_2(line) == True:
count += 1
print("Day 2: %d"% count)
if __name__ == "__main__":
part1();
part2();

1000
day2/input.txt Normal file

File diff suppressed because it is too large Load Diff