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.
 
 

36 lines
839 B

#!/usr/bin/env python3
import sys
def f_overlap(pair):
e1, e2 = pair
l1, h1 = e1
l2, h2 = e2
if l1 <= l2 and h1 >= h2: return True
if l2 <= l1 and h2 >= h1: return True
return False
def overlap(pair):
e1, e2 = pair
l1, h1 = e1
l2, h2 = e2
if l1 <= h2 and h1 >= l2: return True
if l2 <= h1 and h2 >= l1: return True
return False
if __name__ == '__main__':
lines = [line.strip('\n') for line in open(sys.argv[1])]
pairs = [tuple([tuple([int(n) for n in e.split('-')]) for e in l.split(',')]) for l in lines]
# challenge 1
fopairs = list(map(f_overlap,pairs))
res1 = str(sum(fopairs))
print("challenge 1:" + "\n" + res1 + "\n")
# challenge 2
opairs = list(map(overlap,pairs))
res2 = str(sum(opairs))
print("challenge 2:" + "\n" + res2 + "\n")