02
This commit is contained in:
34
02/02-01.py
Normal file
34
02/02-01.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
def is_increasing(l:list[str]) -> bool:
|
||||||
|
for i in range(1,len(l)):
|
||||||
|
pre, n = int(l[i-1]), int(l[i])
|
||||||
|
if pre >= n or n-pre > 3:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def is_decreasing(l:list[str]) -> bool:
|
||||||
|
for i in range(1, len(l)):
|
||||||
|
pre, n = int(l[i - 1]), int(l[i])
|
||||||
|
if pre <= n or pre-n > 3:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_line(lin:str) -> bool:
|
||||||
|
l = lin.split()
|
||||||
|
if is_increasing(l) or is_decreasing(l):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
safe = 0
|
||||||
|
input_file = open("input.txt", "r")
|
||||||
|
for line in input_file:
|
||||||
|
if check_line(line):
|
||||||
|
safe += 1
|
||||||
|
input_file.close()
|
||||||
|
print(f'Safe:{safe}')
|
||||||
37
02/02-02.py
Normal file
37
02/02-02.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
|
def is_increasing(l:list[str]) -> bool:
|
||||||
|
for i in range(1,len(l)):
|
||||||
|
pre, n = int(l[i-1]), int(l[i])
|
||||||
|
if pre >= n or n-pre > 3:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def is_decreasing(l:list[str]) -> bool:
|
||||||
|
for i in range(1, len(l)):
|
||||||
|
pre, n = int(l[i - 1]), int(l[i])
|
||||||
|
if pre <= n or pre-n > 3:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_line(lin:str) -> bool:
|
||||||
|
l = lin.split()
|
||||||
|
for i in range(len(l)):
|
||||||
|
l2 = deepcopy(l)
|
||||||
|
l2.pop(i)
|
||||||
|
if is_increasing(l2) or is_decreasing(l2):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
safe = 0
|
||||||
|
input_file = open("input.txt", "r")
|
||||||
|
for line in input_file:
|
||||||
|
if check_line(line):
|
||||||
|
safe += 1
|
||||||
|
input_file.close()
|
||||||
|
print(f'Safe:{safe}')
|
||||||
6
02/ex.txt
Normal file
6
02/ex.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
7 6 4 2 1
|
||||||
|
1 2 7 8 9
|
||||||
|
9 7 6 2 1
|
||||||
|
1 3 2 4 5
|
||||||
|
8 6 4 4 1
|
||||||
|
1 3 6 7 9
|
||||||
1000
02/input.txt
Normal file
1000
02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user