aboutsummaryrefslogtreecommitdiff
path: root/2024/02/solve.py
blob: 08becc80725f3b8246aeee8236582eae500d421b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()