31 lines
936 B
Python
31 lines
936 B
Python
with open("day4\input.txt") as f:
|
|
data = f.readlines()
|
|
|
|
'''
|
|
|
|
Some of the pairs have noticed that one of their assignments fully contains the other.
|
|
For example, 2-8 fully contains 3-7, and 6-6 is fully contained by 4-6.
|
|
In pairs where one assignment fully contains the other, one Elf in the pair would be
|
|
exclusively cleaning sections their partner will already be cleaning,
|
|
so these seem like the most in need of reconsideration.
|
|
|
|
In how many assignment pairs does one range fully contain the other?
|
|
|
|
'''
|
|
pair_sum = 0
|
|
line:str
|
|
for line in data:
|
|
|
|
elf1 = [int(i) for i in line.split(',')[0].split('-')]
|
|
elf2 = [int(i) for i in line.split(',')[1].split('-')]
|
|
|
|
#Find the smallest
|
|
if elf1[1] - elf1[0] > elf2[1] - elf2[0]:
|
|
if elf2[0] >= elf1[0] and elf2[1] <= elf1[1]:
|
|
pair_sum += 1
|
|
else:
|
|
if elf1[0] >= elf2[0] and elf1[1] <= elf2[1]:
|
|
pair_sum += 1
|
|
|
|
|
|
print(pair_sum) #550 |