From cf052f66f8644d7271f25ea24624737e8556d301 Mon Sep 17 00:00:00 2001 From: FanDabbyDoozy Date: Wed, 4 Dec 2024 21:55:35 +0800 Subject: Create 2B.py --- 2024/2B.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 2024/2B.py diff --git a/2024/2B.py b/2024/2B.py new file mode 100644 index 0000000..cb6d86d --- /dev/null +++ b/2024/2B.py @@ -0,0 +1,55 @@ +res = 0 + + +vals = [] +with open('2.txt', 'r') as file: + for line in file: + parts = line.strip().split(" ") + inlist = [] + for num in parts: + inlist.append(int(num)) + vals.append(inlist) + + +slists = [] + + +for val in vals: + print(val) + isafe = False + + for i in range(len(val)): + row = val.copy() + row.pop(i) + print(row) + + + increasing = False + decreasing = False + safe = True + prev = -1 + + for j in row: + if prev == -1: + prev = j + continue + if prev < j: + increasing = True + elif prev > j: + decreasing = True + if (abs(prev - j) > 3 or prev == j or + (j > prev and decreasing) or (j < prev and increasing) or + (increasing and decreasing) or (not increasing and not decreasing)): + safe = False + break + prev = j + + if safe: + isafe = True + break + + slists.append(isafe) + +res = sum(slists) + +print(res) -- cgit v1.2.3