2024/day2/part2.py

23 lines
522 B
Python
Executable File

#!/usr/bin/env python
from common import Report, ReportList, is_safe, parse
def report_remove(report: Report, index: int) -> Report:
return report[:index] + report[index + 1 :]
def is_safe_dampened(report: Report) -> bool:
return is_safe(report) or any(map(is_safe, map(lambda x: report_remove(report, x[0]), enumerate(report))))
def solve(input: ReportList) -> int:
return len(list(filter(is_safe_dampened, input)))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()