[py] Solve 2022_04
This commit is contained in:
parent
04deaca668
commit
30e11343d1
2 changed files with 18 additions and 1 deletions
13
py/aoc/y2022/d04.py
Normal file
13
py/aoc/y2022/d04.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def solve(inputstr):
|
||||
part1 = 0
|
||||
part2 = 0
|
||||
for line in inputstr.splitlines():
|
||||
elf1, elf2 = line.split(",")
|
||||
s1, e1 = map(int, elf1.split("-"))
|
||||
s2, e2 = map(int, elf2.split("-"))
|
||||
if s1 <= s2 <= e2 <= e1 or s2 <= s1 <= e1 <= e2:
|
||||
part1 += 1
|
||||
if s1 <= e2 and s2 <= e1:
|
||||
part2 += 1
|
||||
print(f"Part 1: {part1}")
|
||||
print(f"Part 2: {part2}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue