This commit is contained in:
Sebastian Seedorf
2020-12-02 08:30:23 +01:00
parent e122bb62a0
commit 5290558a69
3 changed files with 1030 additions and 0 deletions

1000
day02/input.txt Normal file

File diff suppressed because it is too large Load Diff

15
day02/part1.py Normal file
View File

@@ -0,0 +1,15 @@
import re
#2-5 m: mfvxmmm
regex = re.compile(r'(\d+)-(\d+) (\w): (\w+)', re.I)
items = (re.match(regex, x).groups() for x in open("input.txt"))
items = map(lambda x: [int(x[0]), int(x[1]), *x[2:]], items)
def in_range(lower, upper, char, string):
cnt_range = sum(1 for s in string if char == s)
return lower <= cnt_range <= upper
count = sum(1 for x in items if in_range(*x))
print(count)

15
day02/part2.py Normal file
View File

@@ -0,0 +1,15 @@
import re
#2-5 m: mfvxmmm
regex = re.compile(r'(\d+)-(\d+) (\w): (\w+)', re.I)
items = (re.match(regex, x).groups() for x in open("input.txt"))
items = map(lambda x: [int(x[0]), int(x[1]), *x[2:]], items)
def in_range(lower, upper, char, string):
cnt_range = sum(1 for s in string[lower-1]+string[upper-1] if char == s)
return cnt_range == 1
count = sum(1 for x in items if in_range(*x))
print(count)