There's definitely a better answer to this.
parent
041fbb83be
commit
89d7a33abb
|
@ -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.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue