Day 2
This commit is contained in:
1000
day02/input.txt
Normal file
1000
day02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
day02/part1.py
Normal file
15
day02/part1.py
Normal 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
15
day02/part2.py
Normal 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)
|
||||||
Reference in New Issue
Block a user