Add day 4.
This commit is contained in:
parent
261a396ae7
commit
f46cb51c60
19
2022/day4.py
Normal file
19
2022/day4.py
Normal 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
1000
2022/inputs/day4.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user