Files
aoc-2022/2022/4/onestar-1.py
T
2024-11-11 09:05:01 +01:00

24 lines
643 B
Python

count = 0
with open("input.txt", "r") as f:
for line in f.readlines():
line = line.strip("\n")
# "A-B,C-D"
twoelves = line.split(",")
# ["A-B", "C-D"]
# "A-B"
leftelf = twoelves[0].split("-")
# ["A", "B"]
lb1 = int(leftelf[0])
ub1 = int(leftelf[1])
# "C-D"
rightelf = twoelves[1].split("-")
# ["C", "D"]
lb2 = int(rightelf[0])
ub2 = int(rightelf[1])
if ((lb1 <= lb2 and ub1 >= ub2) or # Elf 1 fully covers elf 2
(lb2 <= lb1 and ub2 >= ub1)): # Elf 2 fully covers elf 1
count += 1
print(count)