-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2_p1.py
44 lines (32 loc) · 904 Bytes
/
day2_p1.py
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
# read input_data from file
with open("input_day2_p1.txt", "r") as file:
#with open("test.txt", "r") as file:
input_data = file.readlines()
def check_safety(a):
change = [0] * (len(a)-1)
for i in range(0,len(a)-1):
change[i] = a[i]-a[i+1]
if(all(x>0 for x in change) or all(x<0 for x in change)):
if(all(abs(x)<4 for x in change)):
return True
#Else
return False
total = 0
pad_total = 0
for line in input_data:
nums = [int(num.strip()) for num in line.split()]
if check_safety(nums):
total += 1
pad_total += 1
else:
pad = False
for i in range(0,len(nums)):
temp_nums = nums.copy()
temp_nums.pop(i)
if check_safety(temp_nums):
pad = True
if(pad):
pad_total += 1
print("Safe Lines: ",total)
print("Padded Safe Lines: ",pad_total)
#print("\nSimalarity is: ",simal)