Luna Lailatova
2 years ago
2 changed files with 1035 additions and 0 deletions
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
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) |
Loading…
Reference in new issue