Compare commits
2 Commits
5cd8ecb9ee
...
f6d828c1a1
Author | SHA1 | Date |
---|---|---|
Ben Maurer | f6d828c1a1 | |
Ben Maurer | 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