AdventOfCode/days1-5/day4/day4.py

19 lines
790 B
Python
Raw Normal View History

2022-12-25 15:10:36 +00:00
with open('input.txt', 'r') as f:
2022-12-04 23:01:00 +00:00
inputContent = f.read().splitlines()
containedCount = 0
intersectCount = 0
for line in inputContent:
pair = line.split(',')
startRange1, endRange1 = pair[0].split('-')
startRange2, endRange2 = pair[1].split('-')
if ((int(startRange1) >= int(startRange2) and int(endRange1) <= int(endRange2))
or (int(startRange2) >= int(startRange1) and int(endRange2) <= int(endRange1))):
containedCount += 1
if ((int(endRange1) >= int(startRange2) and int(startRange1) <= int(endRange2))
or (int(endRange2) >= int(startRange1) and int(startRange2) <= int(endRange1))):
intersectCount += 1
print("Contained Count:", containedCount)
print("Intersect Count:", intersectCount)