my solutions for advent of code 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

35 lines
806 B

with open('input4.txt','r') as f:
inp = f.read().splitlines(keepends=False)
score = 0
score1 = 0
for i in inp:
tempa, tempb = i.split(',')
a1, a2 = map(int, tempa.split('-'))
b1, b2 = map(int, tempb.split('-'))
if a1 <= b1:
if a2 >= b2:
score1 += 1
elif b1 <= a1:
if b2 >= a2:
score1 += 1
elif b1 <= a2:
if b2 >= a2:
score1 += 1
for i in inp:
tempa, tempb = i.split(',')
a1, a2 = map(int, tempa.split('-'))
b1, b2 = map(int, tempb.split('-'))
if b1 <= a1 and a1 <= b2:
score += 1
elif b1 <= a2 and a2 <= b2:
score += 1
elif a1 <= b1 and b1 <= a2:
score += 1
elif a1 <= b2 and b2 <= a2:
score += 1
print('Part1', score1)
print('Part2', score)