-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.py
More file actions
79 lines (66 loc) · 1.9 KB
/
day2.py
File metadata and controls
79 lines (66 loc) · 1.9 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
l1 = []
with open("d2.txt", "r") as fin:
lines = fin.readlines()
for x in lines:
l1.append(list(map(int, x.strip().split())))
c = 0
for i in range(len(l1)):
prev = l1[i][0]
incr = (l1[i][1] - prev > 0)
tolerance = 0
for j in range(1, len(l1[i])):
if (l1[i][j] - prev) > 0 and not incr:
tolerance += 1
continue
elif (l1[i][j] - prev) < 0 and incr:
tolerance += 1
continue
elif (l1[i][j] - prev) == 0:
tolerance += 1
continue
if (l1[i][j] - prev > 3 and incr):
tolerance += 1
continue
elif (l1[i][j] - prev < -3 and not incr):
tolerance += 1
continue
prev = l1[i][j]
# same code, but remove 1st element
prev = l1[i][1]
incr = (l1[i][2] - prev > 0)
tolerance2 = 0
for j in range(2, len(l1[i])):
if (l1[i][j] - prev) > 0 and not incr:
tolerance2 += 1
continue
elif (l1[i][j] - prev) < 0 and incr:
tolerance2 += 1
continue
elif (l1[i][j] - prev) == 0:
tolerance2 += 1
continue
if (abs(l1[i][j] - prev) > 3):
tolerance2 += 1
continue
prev = l1[i][j]
# same code, but remove 2nd element
prev = l1[i][0]
incr = (l1[i][2] - prev > 0)
tolerance3 = 0
for j in range(2, len(l1[i])):
if (l1[i][j] - prev) > 0 and not incr:
tolerance3 += 1
continue
elif (l1[i][j] - prev) < 0 and incr:
tolerance3 += 1
continue
elif (l1[i][j] - prev) == 0:
tolerance3 += 1
continue
if (abs(l1[i][j] - prev) > 3):
tolerance3 += 1
continue
prev = l1[i][j]
if (tolerance <= 1 or tolerance2 == 0 or tolerance3 == 0):
c += 1
print(c)