day04
This commit is contained in:
parent
c3cd07ca7b
commit
ee9903ee6a
41
day04.py
Normal file
41
day04.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(2, "input4_test"),
|
||||||
|
(528, "input4"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(4, "input4_test"),
|
||||||
|
(881, "input4"),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_sections(self) -> (list, list):
|
||||||
|
for line in self.getInput():
|
||||||
|
s1, s2 = line.split(",")
|
||||||
|
yield list(sorted(map(int, s1.split("-")))), list(sorted(map(int, s2.split("-"))))
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
count = 0
|
||||||
|
for s1, s2 in self.get_sections():
|
||||||
|
if (s1[0] <= s2[0] and s1[1] >= s2[1]) or (s2[0] <= s1[0] and s2[1] >= s1[1]):
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
count = 0
|
||||||
|
for s1, s2 in self.get_sections():
|
||||||
|
if s1[0] <= s2[0] <= s1[1] or s2[0] <= s1[0] <= s2[1]:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2022, 4)
|
||||||
|
day.run(verbose=True)
|
||||||
1000
inputs/input4
Normal file
1000
inputs/input4
Normal file
File diff suppressed because it is too large
Load Diff
6
inputs/input4_test
Normal file
6
inputs/input4_test
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8
|
||||||
Loading…
Reference in New Issue
Block a user