blob: d32ed34e4493dd793fc3259bfed6950db6f4e321 (
plain)
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
|
input = "data/2_2024.txt"
data = open(input).read().strip()
lines = data.split("\n")
p1, p2 = 0, 0
def is_good(xs):
inc_dec = xs == sorted(xs) or xs == sorted(xs, reverse=True)
ok = True
for i in range(len(xs) - 1):
diff = abs(xs[i] - xs[i + 1])
if not 1 <= diff <= 3:
ok = False
return inc_dec and ok
for i in lines:
xs1 = list(map(int, i.split()))
if is_good(xs1):
p1 += 1
good = False
for j in range(len(xs1)):
xs = xs1[:j] + xs1[j + 1 :]
if is_good(xs):
good = True
if good:
p2 += 1
print(p1)
print(p2)
|