File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,42 @@ def count_safe(reports: list[tuple[int]]) -> int:
34
34
35
35
return safe
36
36
37
+ def count_safe_tolerate (reports : list [tuple [int ]]) -> int :
38
+ safe = 0
39
+
40
+ for report in reports :
41
+ prev = report [0 ]
42
+ sign = None
43
+ levels = 0
44
+
45
+ for pos in report [1 :]:
46
+ dif = pos - prev
47
+
48
+ if abs (dif ) > 3 :
49
+ levels += 1
50
+ elif dif == 0 :
51
+ levels += 1
52
+ elif positive (dif ) != sign and sign is not None :
53
+ levels += 1
54
+ else :
55
+ prev = pos
56
+ sign = positive (dif )
57
+
58
+ if levels > 1 :
59
+ break
60
+ else :
61
+ safe += 1
62
+
63
+ return safe
64
+
37
65
if __name__ == '__main__' :
38
66
# reports = parse_input('test-input')
39
67
reports = parse_input ('input' )
40
68
41
69
# Part 1
42
70
safe = count_safe (reports )
43
71
print (f"{ safe } reports are safe" )
72
+
73
+ # Part 2
74
+ safe = count_safe_tolerate (reports )
75
+ print (f"{ safe } reports are actually safe" )
You can’t perform that action at this time.
0 commit comments