-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday04_camp_cleanup.py
43 lines (33 loc) · 1.07 KB
/
day04_camp_cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
def main(assignments: str) -> None:
count = 0
for pair in assignments.splitlines():
first, second = pair.split(",")
count += fully_contains(first, second)
print("Part One:")
print(count)
count = 0
for pair in assignments.splitlines():
first, second = pair.split(",")
count += overlap(first, second)
print("Part Two:")
print(count)
def fully_contains(first: str, second: str) -> bool:
first_start, first_end = first.split("-")
second_start, second_end = second.split("-")
return (
int(first_start) >= int(second_start) and int(first_end) <= int(second_end)
) or (int(first_start) <= int(second_start) and int(first_end) >= int(second_end))
def overlap(first: str, second: str) -> bool:
first_start, first_end = first.split("-")
second_start, second_end = second.split("-")
return int(first_end) >= int(second_start) and int(first_start) <= int(second_end)
if __name__ == "__main__":
INPUT = """2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
"""
main(INPUT)