diff options
author | Marvin Borner | 2024-12-02 06:30:55 +0100 |
---|---|---|
committer | Marvin Borner | 2024-12-02 06:30:55 +0100 |
commit | a37b1a999421e24ddef1a1931cca8722a076d9a3 (patch) | |
tree | 17d8376c5ebcc956458b42ac8ae5a09ab0e3146f /2024/02/solve.py | |
parent | 04e388e64477894626795bd674fcde934669bcf4 (diff) |
hm
Diffstat (limited to '2024/02/solve.py')
-rwxr-xr-x | 2024/02/solve.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/2024/02/solve.py b/2024/02/solve.py new file mode 100755 index 0000000..08becc8 --- /dev/null +++ b/2024/02/solve.py @@ -0,0 +1,39 @@ +#!/bin/env python + + +L = [[int(i) for i in l.split()] for l in open("input").readlines()] + + +def safe(l): + diffs = [l[i + 1] - l[i] for i in range(len(l) - 1)] + if max(diffs) <= 3 and min(diffs) >= 1 and all(x > 0 for x in diffs): + return 1 + elif min(diffs) >= -3 and max(diffs) <= -1 and all(x < 0 for x in diffs): + return 1 + else: + return 0 + + +def part1(): + res = 0 + + for l in L: + res += safe(l) + + print(res) + + +def part2(): + res = 0 + + for l in L: + for s in [l[:i] + l[i + 1 :] for i in range(len(l))]: + if safe(s): + res += 1 + break + + print(res) + + +part1() +part2() |