Compare commits

...

2 Commits

1 changed files with 36 additions and 0 deletions

36
day_4.py 100644
View File

@ -0,0 +1,36 @@
import aocd
from dotenv import load_dotenv
load_dotenv()
puzzle_input = aocd.get_data(day=4, year=2022)
pairs = puzzle_input.split('\n')
pair_number = 0
contained = 0
overlap = 0
for pair in pairs:
pair = list(map(int, pair.replace(',','-').split('-')))
# Contained
if pair[0] <= pair[2] <= pair[3] <= pair[1]:
contained = contained + 1
elif pair[2] <= pair[0] <= pair[1] <= pair[3]:
contained = contained + 1
else:
pass
# Overlapping
if pair[0] <= pair[2] <= pair[1]:
overlap = overlap + 1
elif pair[0] <= pair[3] <= pair[1]:
overlap = overlap + 1
elif pair[2] <= pair[0] <= pair[3]:
overlap = overlap + 1
elif pair[2] <= pair[1] <= pair[3]:
overlap = overlap + 1
else:
pass
print(f'{contained} of the elves\' tasks are contained by others.')
print(f'{overlap} of the tasks overlap.')