diff --git a/.aoc_tiles/tiles/2024/02.png b/.aoc_tiles/tiles/2024/02.png index 08fc37a..8296469 100644 Binary files a/.aoc_tiles/tiles/2024/02.png and b/.aoc_tiles/tiles/2024/02.png differ diff --git a/2024/2/script.py b/2024/2/script.py index 4700843..28500b6 100644 --- a/2024/2/script.py +++ b/2024/2/script.py @@ -1,21 +1,27 @@ from GhostyUtils import aoc +def is_safe(report) -> True: + diffs = [ln - l for l, ln in zip(report, report[1:])] + safety = ((all(d < 0 for d in diffs) + or all(d > 0 for d in diffs)) + and all(0 < abs(d) <= 3 for d in diffs)) + # print(diffs, safety) + return safety + + def main(): inputs = aoc.read_lines() - safe = 0 - for report in inputs: - report = [int(r) for r in report.split()] - diffs = [ln - l for l, ln in zip(report, report[1:])] - safety = ((all(d < 0 for d in diffs) - or all(d > 0 for d in diffs)) - and all(0 < abs(d) <= 3 for d in diffs)) - if safety: - safe += 1 - print(diffs, safety) - - print("p1:", safe) + reports = [[int(r) for r in report.split()] for report in inputs] + num_safe = sum(1 for report in reports if is_safe(report)) + + print("p1:", num_safe) + + num_safe = sum(1 for report in reports + if any(is_safe(report[:drop] + report[drop+1:]) + for drop in range(len(report)))) + print("p2:", num_safe) if __name__ == "__main__": diff --git a/README.md b/README.md index f7173e1..b946159 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ My solutions to the yearly Advents of Code