| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | from string import ascii_letters
DEBUG=False
def debug(*args):
    if DEBUG:
        print(args)
def within(first, second):
    if ((first[0] <= second[0] and first[1] >= second[1])
        or (second[0] <= first[0] and second[1] >= first[1])):
        return True
    return False
def overlap(first, second):
    if ((first[0] < second[0] and first[1] < second[0])
        or (first[0] > second[1] and first[1] > second[1])
        or (second[0] < first[0] and second[1] < first[0])
        or (second[0] > first[1] and second[1] > first[1])):
        return False
    return True
def main():
    with open("input4.txt", "r") as file:
        inlines = [line.strip() for line in file.readlines()]
    overlaps = []
    range_pairs = []
    for line in inlines:
        first, second = line.split(",")
        sfirst = first.split("-")
        pfirst = (int(sfirst[0]), int(sfirst[1]))
        ssecond = second.split("-")
        psecond = (int(ssecond[0]), int(ssecond[1]))
        
        if overlap(pfirst, psecond):
            overlaps.append(1)
        else:
            overlaps.append(0)
        range_pairs.append((pfirst, psecond))
    
    print(sum(overlaps))
if __name__ == "__main__":
    main()
 |