Initial commit
This commit is contained in:
commit
97a4330bc0
110 changed files with 7006 additions and 0 deletions
26
2024/2/one.py
Normal file
26
2024/2/one.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
with open(input_file) as fd:
|
||||
lines = [line.rstrip() for line in fd.readlines()]
|
||||
|
||||
|
||||
safe_num = 0
|
||||
for line in lines:
|
||||
report = [int(level) for level in line.split(" ")]
|
||||
acc = sorted(report)
|
||||
dec = acc[::-1]
|
||||
if report != acc and report != dec:
|
||||
continue
|
||||
for i in range(len(report)-1):
|
||||
diff = abs(report[i] - report[i+1])
|
||||
if diff < 1 or diff > 3:
|
||||
break
|
||||
else:
|
||||
safe_num += 1
|
||||
print(safe_num)
|
||||
|
||||
|
37
2024/2/two.py
Normal file
37
2024/2/two.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
input_file = sys.argv[1]
|
||||
|
||||
with open(input_file) as fd:
|
||||
lines = [line.rstrip() for line in fd.readlines()]
|
||||
|
||||
|
||||
def is_safe(report) -> bool:
|
||||
acc = sorted(report)
|
||||
dec = acc[::-1]
|
||||
if report != acc and report != dec:
|
||||
return False
|
||||
for i in range(len(report) - 1):
|
||||
diff = abs(report[i] - report[i + 1])
|
||||
if diff < 1 or diff > 3:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
safe_num = 0
|
||||
for line in lines:
|
||||
report = [int(level) for level in line.split(" ")]
|
||||
possible_reports = [report]
|
||||
for i in range(len(report)):
|
||||
rep = report.copy()
|
||||
rep.pop(i)
|
||||
possible_reports.append(rep)
|
||||
for rep in possible_reports:
|
||||
if is_safe(rep):
|
||||
safe_num += 1
|
||||
break
|
||||
|
||||
print(safe_num)
|
Loading…
Add table
Add a link
Reference in a new issue