Added template (see 2022) + Day 2 completed

This commit is contained in:
2024-12-02 07:54:03 +01:00
parent 9d61d24b64
commit f37e249160
8 changed files with 77 additions and 1 deletions

20
day2/common.py Normal file
View File

@@ -0,0 +1,20 @@
type Report = tuple[int, ...]
type ReportList = list[Report]
def parse(filename: str) -> ReportList:
report_list: ReportList = []
with open(filename) as f:
while line := f.readline().strip("\n"):
report: Report = tuple(int(digit) for digit in line.split())
report_list.append(report)
return report_list
def is_safe(report: Report) -> bool:
if not (report == tuple(sorted(report)) or report == tuple(sorted(report, reverse=True))):
return False
for i, value in enumerate(report[:-1]):
if abs(value - report[i + 1]) > 3 or value == report[i + 1]:
return False
return True