123456789101112131415161718192021222324252627282930313233343536373839 |
- 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 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 within(pfirst, psecond):
- overlaps.append(1)
- else:
- overlaps.append(0)
-
- range_pairs.append((pfirst, psecond))
-
- print(sum(overlaps))
-
-
- if __name__ == "__main__":
- main()
|