Add day 4.

This commit is contained in:
Mikaël Capelle 2022-12-05 19:09:55 +01:00
parent 261a396ae7
commit f46cb51c60
2 changed files with 1019 additions and 0 deletions

19
2022/day4.py Normal file
View File

@ -0,0 +1,19 @@
# -*- encoding: utf-8 -*-
import sys
lines = [line.strip() for line in sys.stdin.readlines()]
def make_range(value: str) -> set[int]:
parts = value.split("-")
return set(range(int(parts[0]), int(parts[1]) + 1))
sections = [tuple(make_range(part) for part in line.split(",")) for line in lines]
score_1 = sum(s1.intersection(s2) in (s1, s2) for s1, s2 in sections)
print(f"score 1 is {score_1}")
score_2 = sum(bool(s1.intersection(s2)) for s1, s2 in sections)
print(f"score 1 is {score_2}")

1000
2022/inputs/day4.txt Normal file

File diff suppressed because it is too large Load Diff