39 lines
796 B
Python
39 lines
796 B
Python
import shared
|
|
|
|
|
|
def part1(x):
|
|
internal = 0
|
|
for pair in x:
|
|
l, r = pair.split(",")
|
|
l1, l2 = map(int, l.split("-"))
|
|
r1, r2 = map(int, r.split("-"))
|
|
if l1 <= r1 and l2 >= r2:
|
|
internal += 1
|
|
elif r1 <= l1 and r2 >= l2:
|
|
internal += 1
|
|
print(internal)
|
|
|
|
|
|
def part2(x):
|
|
internal = 0
|
|
for pair in x:
|
|
l, r = pair.split(",")
|
|
ll = list(sorted(map(int, l.split("-"))))
|
|
rl = list(sorted(map(int, r.split("-"))))
|
|
|
|
set1 = set(range(ll[0], ll[1] + 1))
|
|
set2 = set(range(rl[0], rl[1] + 1))
|
|
if bool(set1 & set2):
|
|
internal += 1
|
|
print(internal)
|
|
|
|
|
|
def main():
|
|
rows = [row for row in shared.load(4)]
|
|
part1(rows)
|
|
part2(rows)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|