You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
651 B
34 lines
651 B
2 years ago
|
import aoclib
|
||
|
|
||
|
|
||
|
inp = aoclib.get_input(4, parser=aoclib.parse_lines_with_func(lambda line: line.split(",")))
|
||
|
|
||
|
|
||
|
def to_range(substring):
|
||
|
start, end = [int(x) for x in substring.split("-")]
|
||
|
return list(range(start, end+1))
|
||
|
|
||
|
|
||
|
def part1():
|
||
|
count = 0
|
||
|
for line in inp:
|
||
|
one, two = [set(to_range(x)) for x in line]
|
||
|
if one.issubset(two) or two.issubset(one):
|
||
|
count += 1
|
||
|
|
||
|
return count
|
||
|
|
||
|
|
||
|
def part2():
|
||
|
count = 0
|
||
|
for line in inp:
|
||
|
one, two = [set(to_range(x)) for x in line]
|
||
|
one = set(one)
|
||
|
if one.intersection(two):
|
||
|
count += 1
|
||
|
|
||
|
return count
|
||
|
|
||
|
|
||
|
aoclib.main(part1, part2)
|