34 lines
784 B
Python
34 lines
784 B
Python
#!/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}') |