-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday04.py
49 lines (40 loc) · 1.19 KB
/
day04.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
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 4 10:28:39 2022
@author: Ana
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 3 21:31:53 2022
@author: Ana
"""
def part1():
with open('./data/day04.txt') as handle:
ID = []
count = 0
for group in handle.readlines():
group = group.strip().split(',')
ID.append(group)
groupA = group[0].split('-')
groupB = group[1].split('-')
if int(groupB[0]) <= int(groupA[0]) and int(groupB[1]) >= int(groupA[1]):
count +=1
elif int(groupA[0]) <= int(groupB[0]) and int(groupA[1]) >= int(groupB[1]):
count +=1
print('Part 1:', count)
return ID
def part2(groups):
overlaps = 0
for group in groups:
groupA = group[0].split('-')
groupB = group[1].split('-')
if int(groupB[0]) <= int(groupA[0]) and int(groupB[1]) >= int(groupA[0]):
overlaps += 1
elif int(groupA[0]) <= int(groupB[0]) and int(groupA[1]) >= int(groupB[0]):
overlaps += 1
return overlaps
def main():
p1 = part1()
print('Part 2:', part2(p1))
if __name__ == '__main__':
main()