Commit 9bbdf9c 1 parent de8200d commit 9bbdf9c Copy full SHA for 9bbdf9c
File tree 2 files changed +41
-2
lines changed
2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change
1
+ from pathlib import Path
2
+
3
+ from Day4 import Part1
4
+
5
+ def solve (file_path :Path ) -> int :
6
+ ''' Finds the number of overlapping sections for elf cleaning assignments.
7
+
8
+ Arguments:
9
+ file_path(pathlib.Path): The filepath in which to read data from.
10
+
11
+ Returns:
12
+ Integer representing the answer.
13
+ '''
14
+ cleaning_assignments = Part1 .read_data (file_path )
15
+
16
+ return (sum ([cleaning_overlaps (assignment ) for assignment in cleaning_assignments ]))
17
+
18
+ def cleaning_overlaps (cleaning_assignment ) -> bool :
19
+ ''' Determines if one cleaning assignment overlaps
20
+
21
+ Arguments:
22
+ cleaning_assignment(tuple(tuple(int))): A tuple of tuples containing integers for each cleaning assignment.
23
+
24
+ Returns:
25
+ Returns a boolean if one cleaning assignment overlaps the other
26
+ '''
27
+ first_elf = cleaning_assignment [0 ]
28
+ second_elf = cleaning_assignment [1 ]
29
+
30
+ if first_elf [0 ] <= second_elf [0 ] <= first_elf [1 ]:
31
+ return True
32
+ if first_elf [0 ] <= second_elf [1 ] <= first_elf [1 ]:
33
+ return True
34
+ if second_elf [0 ] <= first_elf [0 ] <= second_elf [1 ]:
35
+ return True
36
+ if second_elf [0 ] <= first_elf [1 ] <= second_elf [1 ]:
37
+ return True
38
+
39
+ return False
Original file line number Diff line number Diff line change 3
3
4
4
5
5
6
- from Day3 import Part1
6
+ from Day4 import Part2
7
7
8
- print (Part1 .solve (Path () / 'Day3 ' / 'input.txt' ))
8
+ print (Part2 .solve (Path () / 'Day4 ' / 'input.txt' ))
You can’t perform that action at this time.
0 commit comments