This commit is contained in:
2024-12-02 09:59:08 +01:00
parent 4620bfb9ef
commit ae0b3d9871
4 changed files with 1077 additions and 0 deletions

34
02/02-01.py Normal file
View 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}')