2022/day04: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
d797b183f4
commit
3d2ce132b7
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from typing import TextIO
|
||||
import pytest
|
||||
|
||||
calories = []
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
|
||||
def part1(sections: TextIO) -> int:
|
||||
overlaps: int = 0
|
||||
|
||||
for line in sections:
|
||||
line = line.strip().split(",")
|
||||
|
||||
first_st = int(line[0].split("-")[0])
|
||||
first_nd = int(line[0].split("-")[1])
|
||||
|
||||
sec_st = int(line[1].split("-")[0])
|
||||
sec_nd = int(line[1].split("-")[1])
|
||||
|
||||
first = list(range(first_st, first_nd + 1))
|
||||
second = list(range(sec_st, sec_nd + 1))
|
||||
|
||||
if first_st in second and first_nd in second:
|
||||
overlaps += 1
|
||||
elif sec_st in first and sec_nd in first:
|
||||
overlaps += 1
|
||||
|
||||
return overlaps
|
||||
|
||||
|
||||
def part2(sections: TextIO) -> int:
|
||||
all_overlaps: int = 0
|
||||
|
||||
for line in sections:
|
||||
line = line.strip().split(",")
|
||||
|
||||
first_st = int(line[0].split("-")[0])
|
||||
first_nd = int(line[0].split("-")[1])
|
||||
|
||||
sec_st = int(line[1].split("-")[0])
|
||||
sec_nd = int(line[1].split("-")[1])
|
||||
|
||||
first = list(range(first_st, first_nd + 1))
|
||||
second = list(range(sec_st, sec_nd + 1))
|
||||
|
||||
if any(i in first for i in second):
|
||||
all_overlaps += 1
|
||||
|
||||
return all_overlaps
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(part1(open("day04.txt")))
|
||||
print(part2(open("day04.txt")))
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from day04 import *
|
||||
|
||||
|
||||
def test_part1() -> None:
|
||||
sections = open("day04.txt")
|
||||
assert part1(sections) == 588
|
||||
sections.close()
|
||||
|
||||
|
||||
def test_part2() -> None:
|
||||
sections = open("day04.txt")
|
||||
assert part2(sections) == 911
|
||||
sections.close()
|
Loading…
Reference in New Issue