2024 Dec 02nd
This commit is contained in:
parent
564643c001
commit
8fa58eca1b
1 changed files with 28 additions and 0 deletions
28
Python/2024/02/main.py
Normal file
28
Python/2024/02/main.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from functools import cmp_to_key
|
||||
input = open("input", 'r')
|
||||
|
||||
data1 = []
|
||||
|
||||
for i, line in enumerate(input):
|
||||
data1.append([int(val.strip()) for val in line.split(" ")])
|
||||
|
||||
sm = 0
|
||||
sm2 = 0
|
||||
|
||||
def checkReport(report):
|
||||
reportDiff = set([a - b for a , b in zip(report, report[1:])])
|
||||
if reportDiff.issubset({1,2,3}):
|
||||
return True
|
||||
if reportDiff.issubset({-1,-2,-3}):
|
||||
return True
|
||||
return False
|
||||
|
||||
for report in data1:
|
||||
sm += 1 if checkReport(report) else 0
|
||||
for i in range(len(report)):
|
||||
if checkReport(report[:i] + report[(i+1):]):
|
||||
sm2 += 1
|
||||
break
|
||||
|
||||
print(sm)
|
||||
print(sm2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue