-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
55 lines (36 loc) · 980 Bytes
/
day2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
from HelperFunctions import readInputFile
from HelperFunctions import readExampleInput
from HelperFunctions import convertToInt
def isSafe(report):
diff = [report[x+1]-report[x] for x in range(len(report)-1)]
if all([x in [-1,-2,-3] for x in diff]) or all([x in [1,2,3] for x in diff]):
return True
return False
def do1(splitInput):
result = 0
for report in splitInput:
report = convertToInt(report.split(' '))
if isSafe(report):
result = result + 1
return result
def do2(splitInput):
result = 0
for report in splitInput:
report = convertToInt(report.split(' '))
if isSafe(report):
result = result + 1
else:
for i in range(len(report)):
adaptedReport = report.copy()
adaptedReport.pop(i)
if isSafe(adaptedReport):
result = result + 1
break
return result
def do():
strInput = readInputFile(2)
splitInput = strInput.split('\n')
print(do1(splitInput))
print(do2(splitInput))
print('done')
do()